As the first step of consuming a wide range of images in Azure, finding up an appropriate virtual machine (VM) image can be critical. In this post, we will see how easily we can find Azure Marketplace VM images using PowerShell.

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.

  1. 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."

  1. 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.

  1. 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.

  1. 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.

Listing all available Azure locations

Listing all available Azure locations

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"
Listing image publishers

Listing image publishers

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"
Listing image offers from the selected publisher

Listing image offers from the selected publisher

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!

Conclusion ^

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.

avatar
0 Comments

Leave a reply

Please enclose code in pre tags

Your email address will not be published. Required fields are marked *

*

© 4sysops 2006 - 2021

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account