When creating virtual machines in Microsoft Azure, you’ll need to know which machine size and image to use (provided you’re not using your own uploaded custom image). Microsoft (and partners) did a great job in providing many pre-defined images for the IaaS platform, however not all images are available in all Azure regions. An image could be available in the South Central U.S location, but not in the “Japan East” region. The same applies to the VM sizes, for example, the Standard_NC6 size (backed by a Tesla K80 GPU) is only available in East U.S. and South Central U.S. locations, not in any of the other locations.
To check which VM sizes and images are available in your target location, can easily be done using PowerShell. To get you started with the Azure CmdLets, refer to my previous post.
Retrieving available locations
First step is figuring out which location you want to use for deploying your resources. If you’ve been using the Azure Portal, the location dropdown menu should be familiar.
The location is needed to create any resource in Azure. In PowerShell you can get a list of available Azure locations, using the Get-AzureRmLocation CmdLet. This will output a list of Azure locations including the location name and display name.
PS C:\Windows\system32> Get-AzureRmLocation Location : eastasia DisplayName : East Asia Providers : {Microsoft.Backup, Microsoft.Batch, Microsoft.ClassicCompute, Microsoft.ClassicNetwork...} Location : southeastasia DisplayName : Southeast Asia Providers : {Microsoft.Automation, Microsoft.Backup, Microsoft.Batch, Microsoft.ClassicCompute...} Location : centralus DisplayName : Central US Providers : {Microsoft.Backup, Microsoft.Batch, Microsoft.ClassicCompute, Microsoft.ClassicNetwork...} ...
Once you find the location you want to use, make not of the name of display name; the CmdLets in the following commands accept both the location name (eg. eastasia) as well as the display name (eg. East Asia).
Getting available VM sizes
Getting the available VM sizes can be done using the Get-AzureRmVMSize CmdLet. The only parameter it needs, is the location. This can either be passed by piping the output of Get-AzureRmLocation CmdLet, or by manually defining the parameter. The following 2 commands will give the same result.
Get-AzureRmLocation | Where-Object {$_.Location -eq "westeurope"} | Get-AzureRmVMSize Get-AzureRmVMSize -Location "West Europe"
Note that the first example uses the location name as input, the second example uses the display name. When you want to use the display name in the first example, you should use the following:
Get-AzureRmLocation | Where-Object {$_.DisplayName -eq "West Europe"} | Get-AzureRmVMSize
The CmdLets output a table of available VM sizes, including information on number of cores, memory, etc.
PS C:\Windows\system32> Get-AzureRmVMSize -Location westeurope Name NumberOfCores MemoryInMB MaxDataDiskCount OSDiskSizeInMB ResourceDiskSizeInMB ---- ------------- ---------- ---------------- -------------- -------------------- Standard_DS1 1 3584 2 1047552 7168 Standard_DS2 2 7168 4 1047552 14336 Standard_DS3 4 14336 8 1047552 28672 Standard_DS4 8 28672 16 1047552 57344 Standard_DS11 2 14336 4 1047552 28672 Standard_DS12 4 28672 8 1047552 57344 Standard_DS13 8 57344 16 1047552 114688 Standard_DS14 16 114688 32 1047552 229376 Standard_A0 1 768 1 1047552 20480 Standard_A1 1 1792 2 1047552 71680 ....
Next, you could do filtering on the list by using the Where-Object CmdLet. For example, if you want to see all VM sizes in West Europe location which have 4 or more cores, you can do the following:
Get-AzureRmVMSize -Location "West Europe" | Where-Object {$_.NumberOfCores -ge 4}
Or, to get the VM sizes which have 2GB or more of RAM (remember that the Get-AzureRmVMSize returns the memory in MB):
Get-AzureRmVMSize -Location "West Europe" | Where-Object {$_.MemoryInMB -ge 2048}
Getting available images
Next step is to get the available images for your location. In the Azure Portal, the VM images can selected when creating a new Virtual Machine. The image selection allows you to search for the images, but it will not tell you if it’s available in your preferred region.
To retrieve the image available in a certain location, you can use the Get-AzureRmVMImage CmdLet. However, the CmdLet uses 4 input parameters. The images in Azure are stored in the following way:
Publisher > Offer > Sku > Image
So the basic steps are:
Each each of these steps (except the “Image” itself) should be passed to the Get-AzureRmVMImage CmdLet. The following CmdLet can be used for this:
- Get-AzureRmVMImagePublisher
- Get-AzureRmVMImageOffer
- Get-AzureRmVMImageSku
All these CmdLets use the “location” parameter as mandatory input. The location parameter can be used as described in the previous chapeter. To start off, we need to figure out the publisher of the image we want to use, so we’ll be using the Get-AzureRmVMImagePublisher CmdLet.
Get-AzureRmVMImagePublisher -Location "West Europe"
This will output a list of ALL available publishers:
PS C:\Windows\system32> Get-AzureRmVMImagePublisher -Location "West Europe" PublisherName Location Id ------------- -------- -- 4psa westeurope /Subscriptions/a0d54dfe-3a27-481f-ad89-09d32b20f05f/... 4ward365 westeurope /Subscriptions/a0d54dfe-3a27-481f-ad89-09d32b20f05f/... 7isolutions westeurope /Subscriptions/a0d54dfe-3a27-481f-ad89-09d32b20f05f/... a10networks westeurope /Subscriptions/a0d54dfe-3a27-481f-ad89-09d32b20f05f/... abiquo westeurope /Subscriptions/a0d54dfe-3a27-481f-ad89-09d32b20f05f/... accellion westeurope /Subscriptions/a0d54dfe-3a27-481f-ad89-09d32b20f05f/... Acronis westeurope /Subscriptions/a0d54dfe-3a27-481f-ad89-09d32b20f05f/... Acronis.Backup westeurope /Subscriptions/a0d54dfe-3a27-481f-ad89-09d32b20f05f/... actian_matrix westeurope /Subscriptions/a0d54dfe-3a27-481f-ad89-09d32b20f05f/... actifio westeurope /Subscriptions/a0d54dfe-3a27-481f-ad89-09d32b20f05f/... active-navigation westeurope /Subscriptions/a0d54dfe-3a27-481f-ad89-09d32b20f05f/... activeeon westeurope /Subscriptions/a0d54dfe-3a27-481f-ad89-09d32b20f05f/... adam-software westeurope /Subscriptions/a0d54dfe-3a27-481f-ad89-09d32b20f05f/... adatao westeurope /Subscriptions/a0d54dfe-3a27-481f-ad89-09d32b20f05f/... adobe westeurope /Subscriptions/a0d54dfe-3a27-481f-ad89-09d32b20f05f/... adobe_test westeurope /Subscriptions/a0d54dfe-3a27-481f-ad89-09d32b20f05f/... adra-match westeurope /Subscriptions/a0d54dfe-3a27-481f-ad89-09d32b20f05f/... advantech westeurope /Subscriptions/a0d54dfe-3a27-481f-ad89-09d32b20f05f/... advantech-webaccess westeurope /Subscriptions/a0d54dfe-3a27-481f-ad89-09d32b20f05f/... ...
Now make note of the publisher you want to get the offers for. If you want a Windows 2016 image deployed, you’ll need to use the “MicrosoftWindowsServer” publisher. Now, to check the offers from this publisher, we use the Get-AzureRmVMImageOffer CmdLet.
Get-AzureRmVMImageOffer -Location "West Europe" -PublisherName MicrosoftWindowsServer
Again, make note of the offer you want to use, for example “WindowsServer”. Now, retrieve the stock keeping units (SKU) for the publisher and offer, using Get-AzureRmVMImageSku:
Get-AzureRmVMImageSku -Location "West Europe" -PublisherName MicrosoftWindowsServer -Offer WindowsServer
PS C:\Windows\system32> Get-AzureRmVMImageSku -Location westeurope -PublisherName MicrosoftWindowsServer -Offer WindowsServer Skus Offer PublisherName Location Id ---- ----- ------------- -------- -- 2008-R2-SP1 WindowsServer MicrosoftWindowsServer westeurope /Subscriptions/a0d54dfe-3a27-481f-ad... 2008-R2-SP1-BYOL WindowsServer MicrosoftWindowsServer westeurope /Subscriptions/a0d54dfe-3a27-481f-ad... 2012-Datacenter WindowsServer MicrosoftWindowsServer westeurope /Subscriptions/a0d54dfe-3a27-481f-ad... 2012-Datacenter-BYOL WindowsServer MicrosoftWindowsServer westeurope /Subscriptions/a0d54dfe-3a27-481f-ad... 2012-R2-Datacenter WindowsServer MicrosoftWindowsServer westeurope /Subscriptions/a0d54dfe-3a27-481f-ad... 2012-R2-Datacenter-BYOL WindowsServer MicrosoftWindowsServer westeurope /Subscriptions/a0d54dfe-3a27-481f-ad... 2016-Datacenter WindowsServer MicrosoftWindowsServer westeurope /Subscriptions/a0d54dfe-3a27-481f-ad... 2016-Datacenter-Server-Core WindowsServer MicrosoftWindowsServer westeurope /Subscriptions/a0d54dfe-3a27-481f-ad... 2016-Datacenter-with-Containers WindowsServer MicrosoftWindowsServer westeurope /Subscriptions/a0d54dfe-3a27-481f-ad... 2016-Nano-Server WindowsServer MicrosoftWindowsServer westeurope /Subscriptions/a0d54dfe-3a27-481f-ad...
Now note the SKU, for example “2016-Nano-Server” and retrieve the available image for that SKU using Get-AzureRmVMImage:
Get-AzureRmVMImage -Location "West Europe" -PublisherName MicrosoftWindowsServer -Offer WindowsServer -Skus "2016-Nano-Server"
This outputs the versions available for that SKU:
PS C:\Windows\system32> Get-AzureRmVMImage -Location "West Europe" -PublisherName MicrosoftWindowsServer -Offer WindowsServer -Skus "2016-Nano-Server" Version FilterExpression Skus Offer PublisherName Location Id ------- ---------------- ---- ----- ------------- -------- -- 2016.0.20161012 2016-Nano-Server WindowsServer MicrosoftWindowsServer westeurope /Subscriptions/a0d... 2016.0.20161109 2016-Nano-Server WindowsServer MicrosoftWindowsServer westeurope /Subscriptions/a0d...
If nothing is returned, there’s no image available in your selected location for that specific SKU. This brings you at the end of the process of the image availability check. Next step could be deploying a VM using the selected image.
Tying it all together
Optionally, you could tie all image-related CmdLets together by piping the commands. For example, you can output ALL available image in a certain location :
Get-AzureRmLocation | Where-Object {$_.DisplayName -eq "West Europe"} | Get-AzureRmVMImagePublisher | Get-AzureRmVMImageOffer | Get-AzureRmVMImageSku | Get-AzureRmVMImage
This command would be running for a while; it will retrieve a lot of data, so I advice you to output the data to a file using Set-Content, Out-File or Export-Csv.
Update
I’ve written 2 scripts which can export the available VM sizes and images to CSV, as I described in my new post. The scripts have been uploaded to the Microsoft Technet Gallery. If you like the scripts, don’t forget to give the scripts a rating on the Microsoft Gallery page.
The script to generate a VM Image (Export-AzureVMImages.ps1) availability matrix is available here: https://gallery.technet.microsoft.com/Generate-Azure-VM-image-756a0119 |
The script to generate a VM Size (Export-AzureVMSizes.ps1) availability matrix is available here: https://gallery.technet.microsoft.com/Generate-Azure-VM-size-3dd9d406 |
I hope this article was useful for you. If you have any questions, don’t hesitate to leave a comment or drop me an e-mail.
Thanks!, I made the script below to quickly look for images when creating templates/scripts..
$loc = Get-AzureRmLocation | OGV -passthru | select Location #first set a location
$publisher=Get-AzureRmVMImagePublisher -Location $loc.Location |OGV -passthru | select publishername #check all the publishers available
$offer=Get-AzureRmVMImageOffer -Location $loc.Location -PublisherName $publisher.PublisherName|OGV -passthru |select offer #look for offers for a publisher
$sku=Get-AzureRmVMImageSku -Location $loc.Location -PublisherName $publisher.PublisherName -Offer $offer.Offer | OGV -passthru |select skus #view SKUs for an offer
$imagesize=Get-AzureRmVMSize -Location $loc.location | OGV -PassThru | select Name
Get-AzureRmVMImage -Location $loc.Location -PublisherName $publisher.PublisherName -Offer $offer.Offer -Skus $sku.Skus #pick one!
Really helpful thanks – especially since the VM selection blade in Azure only lets you specify minimums, I’m usually on a budget so need to specify maximums of mem/cpu !