Когда вы фильтруете изображение с помощью команды CLI: az lab gallery-image list --lab-name mytestlab --resource-group myrg --query "[?name == 'Windows 10 Pro, Version 1903']"
, вы найдете аналогичную ссылку на изображение, за исключением SKU.
Однако для Azure CLI отсутствует параметр SKU az lab vm create .В качестве обходного пути вы можете создать виртуальную машину с DevTest Labs, используя Azure PowerShell.
Пример сценария PowerShell :
[CmdletBinding()]
Param(
[Parameter(Mandatory = $false)] $SubscriptionId,
[Parameter(Mandatory = $true)] $LabResourceGroup,
[Parameter(Mandatory = $true)] $LabName,
[Parameter(Mandatory = $true)] $NewVmName,
[Parameter(Mandatory = $true)] $UserName,
[Parameter(Mandatory = $true)] $Password
)
pushd $PSScriptRoot
try {
if ($SubscriptionId -eq $null) {
$SubscriptionId = (Get-AzContext).Subscription.SubscriptionId
}
$API_VERSION = '2016-05-15'
$lab = Get-AzResource -ResourceId "/subscriptions/$SubscriptionId/resourceGroups/$LabResourceGroup/providers/Microsoft.DevTestLab/labs/$LabName"
if ($lab -eq $null) {
throw "Unable to find lab $LabName resource group $LabResourceGroup in subscription $SubscriptionId."
}
#For this example, we are getting the first allowed subnet in the first virtual network
# for the lab.
#If a specific virtual network is needed use | to find it.
#ie $virtualNetwork = @(Get-AzResource -ResourceType 'Microsoft.DevTestLab/labs/virtualnetworks' -ResourceName $LabName -ResourceGroupName $lab.ResourceGroupName -ApiVersion $API_VERSION) | Where-Object Name -EQ "SpecificVNetName"
$virtualNetwork = @(Get-AzResource -ResourceType 'Microsoft.DevTestLab/labs/virtualnetworks' -ResourceName $LabName -ResourceGroupName $lab.ResourceGroupName -ApiVersion $API_VERSION)[0]
$labSubnetName = $virtualNetwork.properties.allowedSubnets[0].labSubnetName
#Prepare all the properties needed for the createEnvironment
# call used to create the new VM.
# The properties will be slightly different depending on the base of the vm
# (a marketplace image, custom image or formula).
# The setup of the virtual network to be used may also affect the properties.
# This sample includes the properties to add an additional disk under dataDiskParameters
$parameters = @{
"name" = $NewVmName;
"location" = $lab.Location;
"properties" = @{
"labVirtualNetworkId" = $virtualNetwork.ResourceId;
"labSubnetName" = $labSubnetName;
"notes" = "Windows Server 2016 Datacenter";
"osType" = "windows"
"expirationDate" = "2019-12-01"
"galleryImageReference" = @{
"offer" = "WindowsServer";
"publisher" = "MicrosoftWindowsServer";
"sku" = "2016-Datacenter";
"osType" = "Windows";
"version" = "latest"
};
"size" = "Standard_DS2_v2";
"userName" = $UserName;
"password" = $Password;
"disallowPublicIpAddress" = $true;
"dataDiskParameters" = @(@{
"attachNewDataDiskOptions" = @{
"diskName" = "adddatadisk"
"diskSizeGiB" = "1023"
"diskType" = "Standard"
}
"hostCaching" = "ReadWrite"
})
}
}
#The following line is the same as invoking
# https://azure.github.io/projects/apis/#!/Labs/Labs_CreateEnvironment rest api
Invoke-AzResourceAction -ResourceId $lab.ResourceId -Action 'createEnvironment' -Parameters $parameters -ApiVersion $API_VERSION -Force -Verbose
}
finally {
popd
}
Команда предоставляет пример запуска сценария, сохраненного в имени файла: Create-LabVirtualMachine.ps1.
PS> .\Create-LabVirtualMachine.ps1 -ResourceGroupName 'MyLabResourceGroup' -LabName 'MyLab' -userName 'AdminUser' -password 'Password1!' -VMName 'MyLabVM'