0
votes

I need to create a Windows 10 VM in Azure through a script that can be called in a CI pipeline in order to create a nested android emulator for automated UI testing. The script creates the VM using the new Azure powershell modules (in this case Az.Compute), but it seems that the cmdlet New-AzVm only accepts a limited list of image names in its -ImageName parameter. Is there a way to specify to this cmdlet that I want to create a Windows 10 VM?

I have tried using the format Publisher:Offer:Sku:Version for a Windows 10 Pro image, but it was unable to recognize this format.

$ImageName = "MicrosoftWindowsDesktop:Windows10:rs5-pro:latest"

# Create the VM
New-AzVM `
  -ResourceGroupName $ResourceGroup `
  -Name $VmName `
  -Location $Location `
  -ImageName $ImageName `
  -Size $VmSize `
  -VirtualNetworkName $VnetName `
  -SubnetName $SubnetName `
  -SecurityGroupName $NsgName `
  -PublicIpAddressName $PipName `
  -Credential $Cred `
  -OpenPorts 3389 `
  -Verbose

I expected to have a windows 10 vm created in my azure resource group, but instead received the following error:

New-AzVM : Artifact: VMImage was not found. At line:1 char:1 + New-AzVM -ResourceGroup androidexample -Location eastus -ImageName "M ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [New-AzVM], CloudException + FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.NewAzureVMCommand

1

1 Answers

1
votes

I think it should be "windows-10" instead of windows10. Moreover, use "rs5-pron" or "rs4-pro" instead of "rs5-pro". Also use specific versions like :

"17763.678.1908092216" "17763.737.1909062324"

You can list the offers for example, for west Europe using:

$locName="westeurope"
$pubName="MicrosoftWindowsDesktop"
Get-AzVMImageOffer -Location $locName -PublisherName $pubName | Select Offer

Also for listing SKUs you can use

Get-AzVMImageSku -Location $locName -PublisherName $pubName -Offer $offerName | Select Skus

Also for listing image versions you can use (for example, here for rs5-pron):

$skuName="rs5-pron"
Get-AzVMImage -Location $locName -PublisherName $pubName -Offer $offerName -Sku $skuName | Select Version 

Hope this helps :).