- Create and manage append blobs with PowerShell - Wed, Oct 12 2022
- Permanently delete a Key Vault in Azure using PowerShell - Fri, Feb 4 2022
- Restore Azure Files with PowerShell - Fri, Jan 28 2022
Each image in Azure Marketplace has a unique name, which may not be easy to remember. Especially when it comes to spinning up VMs using Azure Resource Manager (ARM) templates or PowerShell scripts, we must specify the exact names of the images in the code. Fortunately, PowerShell already has some useful cmdlets for managing Azure VM images including quickly listing the names of the source images.
Steps to find Azure VM images
Let's assume we are looking for Windows Server 2016 images, but we don't know which versions and stock keeping units (SKUs) are available. In this scenario, we'll have four steps to find our target VM image.
- Specify the location
Because each Azure region might have a different image portfolio, it is important to ensure the image we are looking for exists in our region. In our case, I will be choosing "West Europe."
- Define the correct publisher
After specifying the location, we must pick a publisher to proceed. Publishers are basically image providers from which we will choose the correct offers and SKUs afterward. In this scenario, I will be selecting MicrosoftWindowsServer.
- Find the offer
Publishers might have many different offers. So we need to find the correct offer we're looking for. I will be looking for WindowsServer.
- Pick the SKU (version)
In this last step, PowerShell will list all available SKUs in the specified location, and you have to select the SKU that best suits your needs.
Using PowerShell to find an SKU
Let's get started with the first step. To list all available locations in Azure and store the user input in a variable, we are going to use the following command:
$locname=Get-AzureRmLocation | ` select displayname | ` Out-GridView -PassThru -Title "Choose a location"
PowerShell will then prompt us to choose a location as shown below.
The following command will now use the location information we've picked. It will ask us to choose a publisher from the specified location (the second step).
$pubname=Get-AzureRmVMImagePublisher ` -Location $locname.DisplayName | ` Out-GridView -PassThru -Title "Choose a publisher"
This third step expects us to choose an image offer based on the location and publisher selections we made earlier.
$offername = Get-AzureRmVMImageOffer ` -Location $locname.DisplayName ` -PublisherName $pubname.PublisherName | ` Out-GridView -PassThru -Title "Choose an offer"
After taking the last input from the user, PowerShell will list all available SKUs based on our selections.
$title="SKUs for location: " + ` $locname.DisplayName + ` ", Publisher: " + ` $pubname.PublisherName + ` ", Offer: " + ` $offername.Offer Get-AzureRmVMImageSku ` -Location $locname.DisplayName ` -PublisherName $pubname.PublisherName ` -Offer $offername.Offer | ` select SKUS | ` Out-GridView -Title $title
In my scenario, PowerShell lists seven different Windows Server 2016 images.
All available SKUs based on the selections made
I can now define any of these source images in Azure using their SKUs shown above when creating a new Azure VM using PowerShell (step 4).
Subscribe to 4sysops newsletter!
It is very time-saving to find out which VM images are currently available in our region since it is getting more important to automate tasks such as creating VMs in Azure. Using a couple of easy cmdlets allows us to pick the correct images from Azure Marketplace and use them in our scripts.
Want to write for 4sysops? We are looking for new authors.