Search code examples
azureazure-powershell

Creating an Azure VM with powershell


I am trying to create an Azure VM with Windows 10 pro with the following command but I am unable.

New-AzVm -ResourceGroupName "lab2023" -Name 'vmlab' -Location "canadacentral" -Image "win10-22h2-pro" -VirtualNetworkName "lab2023-vnet" -SubnetName "lab2023-subnet" -SecurityGroupName 'labvm-nsg' -PublicIpAddressName 'vm-ip' ` -OpenPorts 3389

I receive this error [enter image description here](https://i.sstatic.net/8dhA8.png)

I am trying to find the name of the image, but no luck.

I want to make it very easy command to understand


Solution

  • The Image parameter is a structured value built up from several pieces of information as per documentation:

    Now you can combine the selected publisher, offer, SKU, and version into a URN (values separated by :). Pass this URN with the -Image parameter when you create a VM with the New-AzVM cmdlet. You can also replace the version number in the URN with latest to get the latest version of the image.

    Some examples of image urns are here although I cannot find one for Windows 10, and the resulting command looks like:

    New-AzVm -ResourceGroupName "myResourceGroupVM" -Name "myVM2" -Location "EastUS" -VirtualNetworkName "myVnet" -SubnetName "mySubnet" -SecurityGroupName "myNetworkSecurityGroup" -PublicIpAddressName "myPublicIpAddress2" -ImageName "MicrosoftWindowsServer:WindowsServer:2016-Datacenter-with-Containers:latest" -Credential $cred -AsJob