Finding the SKUs of Azure VMs images with Powershell
0 min read
I always struggle to know what to put in the imageReference node of the storageProfile node for an Azure VM when I want to automate the creation process through ARM (Azure Resource Manager) templates.
We can find all of those using the Azure PowerShell modules. Below is a small script to automate the creation of the imageReference node where you can find and filter through the different location, publishers, offers and skus to get what you need.
1 2 3 4 5 6 7 |
$location = Get-AzLocation | select displayname | Out-GridView -PassThru -Title "Choose a location" $publisher = Get-AzVMImagePublisher -Location $location.DisplayName | Out-GridView -PassThru -Title "Choose a publisher" $offer = Get-AzVMImageOffer -Location $location.DisplayName -PublisherName $publisher.PublisherName | Out-GridView -PassThru -Title "Choose an offer" $title = "VM SKUs for {0} {1} {2}" -f $location.DisplayName, $publisher.PublisherName, $offer.Offer $sku = Get-AzVMImageSku -Location $location.DisplayName -PublisherName $publisher.PublisherName -Offer $offer.Offer | select SKUS | Out-GridView -Title $title -PassThru $imageReference = @{ publisher = $publisher.PublisherName; offer = $offer.Offer; sku = $sku.Skus; version = "latest" } $imageReference | ConvertTo-Json -Depth 4 |
Happy ARMing!