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
⚠️
windows_tools
Summary:
The documentation page exhibits a Windows bias by providing only Azure PowerShell examples for scripting and automation, with no equivalent CLI or Bash examples for Linux users. The prerequisites and instructions for command-line usage focus exclusively on PowerShell, and there is no mention of Azure CLI or Linux-native tooling. The documentation also refers to running PowerShell scripts as a primary example of artifact usage, and the PowerShell environment is emphasized in the prerequisites.
Recommendations:
- Add equivalent Azure CLI (az) examples for all PowerShell scripts and commands, demonstrating how to add artifacts to VMs using the CLI.
- Include Bash script examples or references for Linux users, especially in automation scenarios.
- In the prerequisites, mention both PowerShell and Azure CLI as supported options, and provide installation/use instructions for both.
- When describing artifact capabilities, give equal prominence to Bash and Linux scripting as to PowerShell.
- Ensure screenshots and UI descriptions are platform-neutral or show parity between Windows and Linux workflows.
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"
}