Table of Contents
This article describes how to use Azure PowerShell to find VM images in the Azure Marketplace. You can then specify a Marketplace image and plan information when you create a VM.
Terminology
A Marketplace image in Azure has the following attributes:
- Publisher: The organization that created the image. Examples: Canonical, MicrosoftWindowsServer
- Offer: The name of a group of related images created by a publisher. Examples: UbuntuServer, WindowsServer
- SKU: An instance of an offer, such as a major release of a distribution. Examples: 18.04-LTS, 2019-Datacenter
- Version: The version number of an image SKU.
List Publishers
Before you begin, let’s connect to Microsoft Azure using PowerShell.
You can use PowerShell to narrow down a list of images. Replace the values of the variables to meet your needs.
List the image publishers using Get-AzVMImagePublisher.
$locName="EastUS"
Get-AzVMImagePublisher -Location $locName | Select PublisherName
For example, we’ll get the list of the Publishes for Windows OS in the East US location.:
PS C:\> Get-AzVMImagePublisher -Location $locName | `
Where-Object { ($_.PublisherName -like '*MicrosoftWindows*')}
#Output
PublisherName Location
------------- --------
MicrosoftWindowsDesktop eastus
MicrosoftWindowsServer eastus
MicrosoftWindowsServerHPCPack eastus
List Image Offers
For a given publisher, list their offers using Get-AzVMImageOffer.
$pubName="<publisher>"
Get-AzVMImageOffer -Location $locName -PublisherName $pubName | Select Offer
For example, we’ll get the list of image offers for Windows Desktop.
PS C:\> $locName = "EastUS"
PS C:\> $pubName = "MicrosoftWindowsDesktop"
PS C:\> Get-AzVMImageOffer -Location $locName -PublisherName $pubName | Select Offer
#Output
Offer
-----
Windows-10
windows-10-1607-vhd-client-prod-stage
windows-10-1803-vhd-client-prod-stage
windows-10-1809-vhd-client-office-prod-stage
windows-10-1809-vhd-client-prod-stage
windows-10-20h2-vhd-client-office-prod-stage
windows-10-20h2-vhd-client-prod-stage
windows-10-ppe
windows-11
windows-7
windows-7-0-sp1-vhd-client-prod-stage
windows-ent-cpc
windows-evd
windows10preview
windows11preview
windows11preview-arm64
List Image Skus
For a given publisher and offer, list the SKUs available using Get-AzVMImageSku.
$offerName="<offer>"
Get-AzVMImageSku -Location $locName -PublisherName $pubName -Offer $offerName | Select Skus
PS C:\> $locName = "EastUS"
PS C:\> $pubName = "MicrosoftWindowsDesktop"
PS C:\> $offerName = "windows-11"
PS C:\> Get-AzVMImageSku -Location $locName -PublisherName $pubName -Offer $offerName | Select Skus
#Output
Skus
----
win11-21h2-avd
win11-21h2-ent
win11-21h2-entn
win11-21h2-pro
win11-21h2-pro-zh-cn
win11-21h2-pron
win11-22h2-avd
win11-22h2-ent
win11-22h2-entn
win11-22h2-pro
win11-22h2-pro-zh-cn
win11-22h2-pron
List Images
For a SKU, list the versions of the image using Get-AzVMImage.
$skuName="<SKU>"
Get-AzVMImage -Location $locName -PublisherName $pubName -Offer $offerName -Sku $skuName
PS C:\> $locName = "EastUS"
PS C:\> $pubName = "MicrosoftWindowsDesktop"
PS C:\> $offerName = "windows-11"
PS C:\> $skuName= "win11-22h2-pro"
PS C:\> Get-AzVMImage -Location $locName -PublisherName $pubName -Offer $offerName -Sku $skuName
#Output
Version
-------
22621.1105.230107
22621.1265.230207
22621.1413.230310
22621.819.221105
22621.963.221209
Now you can combine the selected publisher, offer, SKU, and version into a URN. Pass this URN with the -Image parameter when you create a VM with the New-AzVM cmdlet. You can also replace the version number in the URN with latest to get the latest version of the image.
Create a new VM from a marketplace image
If you already have the information about what image you want to use, you can pass that information into Set-AzVMSourceImage cmdlet to add image information to the VM configuration.
...
$vmConfig = New-AzVMConfig -VMName "myVM" -VMSize Standard_D1
# Set the Marketplace image
$publisherName = "MicrosoftWindowsServer"
$offerName = "WindowsServer"
$skuName = "2019-Datacenter"
$version = "latest"
$vmConfig = Set-AzVMSourceImage
-VM $vmConfig
-PublisherName $publisherName
-Offer $offerName
-Skus $skuName
-Version $version
...
$locName="EastUS"
Get-AzVMImagePublisher -Location $locName | Select PublisherName
$pubName="<publisher>"
Get-AzVMImageOffer -Location $locName -PublisherName $pubName | Select Offer
$offerName="<offer>"
Get-AzVMImageSku -Location $locName -PublisherName $pubName -Offer $offerName | Select Skus
$skuName="<SKU>"
Get-AzVMImage -Location $locName -PublisherName $pubName -Offer $offerName -Sku $skuName