Problem:
Update a list of VM SKU’s for an Azure Subscription, ensuring that all deprecated SKU’s are not in the list.
Solution:
Using PowerShell, you can run my script to get all the VM SKU’s available to your Azure subscription. To run the script, you will need the AZ module. Here are the steps to run the script:
- Download the script from my Github repo.
- Open PowerShell. This script requires the AZ module.
- Change your working directory to the folder where you downloaded the script.
- Call the script. See below for an example:
.\Get-AzureVirtualMachineSkus.ps1
- Remove the deprecated VM SKU’s from the list. You have now collected all the supported VM SKU’s for all the regions but this list contains deprecated (a.k.a previous generation) VM SKU’s. You must reference the “Previous generations of virtual machine sizes” webpage on Microsoft’s Docs website to find the deprecated VM SKU’s and manually remove the deprecated SKU’s from your list.
Explanation:
When I was first presented with this problem, my initial thought was that I could resolve this with a simple, one-liner in PowerShell. Unfortunately, it wasn’t that simple. Every Azure datacenter supports different VM SKU’s. For instance, the West US 2 region supports the NVv4 series while the West US region does not support this series. So all the regions have to be queried and deduped. Also, when getting the VM SKU’s for a particular region, there isn’t a property on the output that states whether the VM SKU is supported or deprecated. This requires the list to be manually managed to get the desired output. The list below steps through the code and explains its purpose:
- Login to your Azure subscription.
Connect-AzAccount
- Enumerate all the regions (a.k.a. locations) supported by your subscription.
$Regions = (Get-AzLocation).Location
- Loop through the regions and get all the supported VM SKU’s for that region. All the regions will be stored in a new variable called “AllSizeData”.
$AllSizeData = @()
foreach($Region in $Regions)
{
$AllSizeData += (Get-AzVMSize -Location $Region -ErrorAction SilentlyContinue).Name
}
- The data is now collected but we have duplicates and we need to sort the data to make it easier to consume. The “Select-Object” cmdlet can remove duplicates with the “Unique” switch. The “Sort-Object” cmdlet can sort your output.
$FilteredData = $AllSizeData | Select-Object -Unique | Sort-Object