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 detailed automation instructions and scripts exclusively for Azure PowerShell, with no equivalent Bash or Linux-native examples. While the Azure CLI is briefly mentioned, all step-by-step automation is shown using PowerShell, and the script is written in a Windows-centric style. There are no Linux/Bash shell examples or references to cross-platform scripting approaches.
Recommendations:
- Provide equivalent automation instructions and sample scripts using Azure CLI with Bash, suitable for Linux and macOS users.
- Include explicit Bash/Linux command-line examples for deploying ARM templates and managing DevTest Labs environments.
- Ensure that references to automation tools (PowerShell, CLI) are presented in parallel, with neither platform prioritized over the other.
- Add notes or sections clarifying cross-platform compatibility and any OS-specific considerations.
- Where screenshots or UI instructions are given, clarify that the Azure portal is web-based and platform-agnostic.
Create pull request
Flagged Code Snippets
#Requires -Module Az.Resources
[CmdletBinding()]
param (
# ID of the Azure subscription for the lab
[string] [Parameter(Mandatory=$true)] $SubscriptionId,
# Name of the lab in which to create the environment
[string] [Parameter(Mandatory=$true)] $LabName,
# Name of the template repository connected to the lab
[string] [Parameter(Mandatory=$true)] $RepositoryName,
# Name of the template (folder name in the GitHub repository)
[string] [Parameter(Mandatory=$true)] $TemplateName,
# Name of the environment to create in the lab
[string] [Parameter(Mandatory=$true)] $EnvironmentName,
# The parameters to pass to the template. Each parameter is prefixed with "-param_".
# For example, if the template has a parameter named "TestVMName" with a value of "MyVMName",
# the string in $Params is "-param_TestVMName MyVMName".
# This convention allows the script to dynamically handle different templates.
[Parameter(ValueFromRemainingArguments=$true)]
$Params
)
# Sign in to Azure, or comment out this statement to completely automate environment creation.
Connect-AzAccount
# Select the subscription for your lab.
Set-AzContext -SubscriptionId $SubscriptionId | Out-Null
# Get the user ID to use later in the script.
$UserId = $((Get-AzADUser -UserPrincipalName ((Get-AzContext).Account).Id).Id)
# Get the lab location.
$lab = Get-AzResource -ResourceType "Microsoft.DevTestLab/labs" -Name $LabName
if ($lab -eq $null) { throw "Unable to find lab $LabName in subscription $SubscriptionId." }
# Get information about the repository connected to your lab.
$repository = Get-AzResource -ResourceGroupName $lab.ResourceGroupName `
-ResourceType 'Microsoft.DevTestLab/labs/artifactsources' `
-ResourceName $LabName `
-ApiVersion 2016-05-15 `
| Where-Object { $RepositoryName -in ($_.Name, $_.Properties.displayName) } `
| Select-Object -First 1
if ($repository -eq $null) { throw "Unable to find repository $RepositoryName in lab $LabName." }
# Get information about the ARM template base for the environment.
$template = Get-AzResource -ResourceGroupName $lab.ResourceGroupName `
-ResourceType "Microsoft.DevTestLab/labs/artifactSources/armTemplates" `
-ResourceName "$LabName/$($repository.Name)" `
-ApiVersion 2016-05-15 `
| Where-Object { $TemplateName -in ($_.Name, $_.Properties.displayName) } `
| Select-Object -First 1
if ($template -eq $null) { throw "Unable to find template $TemplateName in lab $LabName." }
# Build the template parameters by using parameter names and values.
$parameters = Get-Member -InputObject $template.Properties.contents.parameters -MemberType NoteProperty | Select-Object -ExpandProperty Name
$templateParameters = @()
# Extract the custom parameters from $Params and format them as name/value pairs.
$Params | ForEach-Object {
if ($_ -match '^-param_(.*)' -and $Matches[1] -in $parameters) {
$name = $Matches[1]
} elseif ( $name ) {
$templateParameters += @{ "name" = "$name"; "value" = "$_" }
$name = $null #reset name variable
}
}
# Create an object to hold the necessary template properties.
$templateProperties = @{ "deploymentProperties" = @{ "armTemplateId" = "$($template.ResourceId)"; "parameters" = $templateParameters }; }
# Deploy the environment in your lab by using the New-AzResource command.
New-AzResource -Location $Lab.Location `
-ResourceGroupName $lab.ResourceGroupName `
-Properties $templateProperties `
-ResourceType 'Microsoft.DevTestLab/labs/users/environments' `
-ResourceName "$LabName/$UserId/$EnvironmentName" `
-ApiVersion '2016-05-15' -Force
Write-Output "Environment $EnvironmentName completed."
./deployenv.ps1 -SubscriptionId "000000000-0000-0000-0000-0000000000000" -LabName "mydevtestlab" -ResourceGroupName "mydevtestlabRG000000" -RepositoryName "myRepository" -TemplateName "ARM template folder name" -EnvironmentName "myNewEnvironment"