Close

12th May 2020

How to get the available Azure VM sizes with – Get-AzureRmVMSize

How to get the available Azure VM sizes with – Get-AzureRmVmSize

I was recently working with a customer who was struggling to get a list of available Azure VM sizes for the locations he wanted to deploy Az IaaS VMs.  Whilst I work mainly with VMware technologies a customer is a customer, so I was more than happy to help.

PowerShell

As luck would have it there is a PowerShell module to provide just the information that he was after, Get-AzureRmVmSize.  Included in the AzureRm.Compute PowerShell module.  Assuming you have the modules installed and are already connected to Azure ‘connect-AzureRmAccount’; simple syntax for using this command to pull the VM sizes for the UK West region is;

‘Get-AzureRmVMSize -Location ukwest’

Capture multiple regions and export to CSV

Having a list in PowerShell for a single location is a good first step but what if you want to capture multiple regions?  The following script does exactly that;

'$locations = $null
$vmsizes = $null
$locations = Get-AzureRmLocation | Where-Object {$_.location -in "ukwest","uksouth"}

foreach ($l in $locations)
{
$vmSizes += Get-AzureRmVmSize -Location $l.Location | Select-Object @{Name="LocationDisplayName"; Expression = {$l.DisplayName}},@{Name="Location"; Expression = {$l.Location}},Name,NumberOfCores,MemoryInMB,MaxDataDiskCount,OSDiskSizeInMB,ResourceDiskSizeInMB
}

$vmSizes | Export-Csv -Path "AzureVmSizes.csv" -NoTypeInformation'

This script nulls the variables $locations and $vmsizes (to avoid data being appended).  It then sets a variable $locations to the selected Azure regions then for each location listed it performs the Get-AzureRmVMSize, capturing the information we’re interested in, Cores, Name etc… and then exports to a CSV file.

Super useful and very simple to do.

Thanks

Simon