About This Page
This page is part of the Azure documentation. It contains code examples and configuration instructions for working with Azure services.
Bias Analysis
Bias Types:
⚠️
powershell_heavy
⚠️
windows_first
⚠️
missing_linux_example
Summary:
The documentation page demonstrates a Windows bias by providing only Azure PowerShell examples for scripting and automation, with no equivalent examples for Linux users (e.g., Azure CLI, Bash). The prerequisites and automation sections focus exclusively on PowerShell, and the portal instructions do not clarify cross-platform considerations. There is no mention of Linux-native tooling or scripting approaches, and the only command-line automation path described is via PowerShell, which is traditionally associated with Windows environments.
Recommendations:
- Add equivalent Azure CLI and/or Bash examples for adding artifacts to VMs, ensuring Linux users have clear, native instructions.
- In the prerequisites section, mention both Azure PowerShell and Azure CLI as supported automation tools, with links to installation and usage guides for each.
- Where scripting is discussed, provide both PowerShell and Bash/CLI scripts side-by-side or in tabs, so users on any platform can follow along.
- Clarify in the introduction and relevant sections that both Windows and Linux VMs and users are supported, and provide examples that reflect this parity.
- If certain features are only available via PowerShell, explicitly state this and provide workarounds or alternatives for Linux users where possible.
Create pull request
Flagged Code Snippets
param (
[Parameter(Mandatory=$true, HelpMessage="The ID of the subscription that contains the lab")]
[string] $SubscriptionId,
[Parameter(Mandatory=$true, HelpMessage="The name of the lab that has the VM")]
[string] $DevTestLabName,
[Parameter(Mandatory=$true, HelpMessage="The name of the VM")]
[string] $VirtualMachineName,
[Parameter(Mandatory=$true, HelpMessage="The repository where the artifact is stored")]
[string] $RepositoryName,
[Parameter(Mandatory=$true, HelpMessage="The artifact to apply to the VM")]
[string] $ArtifactName,
[Parameter(ValueFromRemainingArguments=$true)]
$Params
)
# Set the appropriate subscription
Set-AzContext -SubscriptionId $SubscriptionId | Out-Null
# Get the lab resource group name
$resourceGroupName = (Get-AzResource -ResourceType 'Microsoft.DevTestLab/labs' | Where-Object { $_.Name -eq $DevTestLabName}).ResourceGroupName
if ($resourceGroupName -eq $null) { throw "Unable to find lab $DevTestLabName in subscription $SubscriptionId." }
# Get the internal repository name
$repository = Get-AzResource -ResourceGroupName $resourceGroupName `
-ResourceType 'Microsoft.DevTestLab/labs/artifactsources' `
-ResourceName $DevTestLabName `
-ApiVersion 2016-05-15 `
| Where-Object { $RepositoryName -in ($_.Name, $_.Properties.displayName) } `
| Select-Object -First 1
if ($repository -eq $null) { "Unable to find repository $RepositoryName in lab $DevTestLabName." }
# Get the internal artifact name
$template = Get-AzResource -ResourceGroupName $resourceGroupName `
-ResourceType "Microsoft.DevTestLab/labs/artifactSources/artifacts" `
-ResourceName "$DevTestLabName/$($repository.Name)" `
-ApiVersion 2016-05-15 `
| Where-Object { $ArtifactName -in ($_.Name, $_.Properties.title) } `
| Select-Object -First 1
if ($template -eq $null) { throw "Unable to find template $ArtifactName in lab $DevTestLabName." }
# Find the VM in Azure
$FullVMId = "/subscriptions/$SubscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.DevTestLab/labs/$DevTestLabName/virtualmachines/$virtualMachineName"
$virtualMachine = Get-AzResource -ResourceId $FullVMId
# Generate the artifact id
$FullArtifactId = "/subscriptions/$SubscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.DevTestLab/labs/$DevTestLabName/artifactSources/$($repository.Name)/artifacts/$($template.Name)"
# Handle the input parameters to pass through
$artifactParameters = @()
# Fill the artifact parameter with the additional -param_ data and strip off the -param_
$Params | ForEach-Object {
if ($_ -match '^-param_(.*)') {
$name = $_ -replace '^-param_'
} elseif ( $name ) {
$artifactParameters += @{ "name" = "$name"; "value" = "$_" }
$name = $null #reset name variable
}
}
# Create a structure to pass the artifact data to the action
$prop = @{
artifacts = @(
@{
artifactId = $FullArtifactId
parameters = $artifactParameters
}
)
}
# Apply the artifact
if ($virtualMachine -ne $null) {
# Apply the artifact by name to the virtual machine
$status = Invoke-AzResourceAction -Parameters $prop -ResourceId $virtualMachine.ResourceId -Action "applyArtifacts" -ApiVersion 2016-05-15 -Force
if ($status.Status -eq 'Succeeded') {
Write-Output "##[section] Successfully applied artifact: $ArtifactName to $VirtualMachineName"
} else {
Write-Error "##[error]Failed to apply artifact: $ArtifactName to $VirtualMachineName"
}
} else {
Write-Error "##[error]$VirtualMachine was not found in the DevTest Lab, unable to apply the artifact"
}