FAQ: Find Latest Version of Image in Azure

Get the newest version of an Azure image with a few lines of PowerShell.

John Savill

July 30, 2014

1 Min Read
new version

Q: How can I easily find the latest version of an image in Azure?

A: Microsoft provides multiple versions of many images based on patch levels. Often you just want to use the latest version of an image. I created a PowerShell script that fetches all the versions for a specific operating system (which you can change) and then orders the versions so the newest version is the first element:

$images = Get-AzureVMImage$2012R2imgs = @() #Create array of objectsforeach ($image in $images){   $image.Label   if ($image.Label.Contains("Windows Server 2012 R2 Datacenter"))   {      $2012R2imgs += $image   }}$2012R2imgs = $2012R2imgs | Sort-Object PublishedDate -Descending #put the newest first which is the highest patched version$2012R2imgs | ft Label,ImageName,LogicalSizeInGB -AutoSize

To use the latest version, just access the element $2012R2imgs[0] (for example, as part of provisioning I would use -ImageName $2012R2imgs[0].ImageName). The following code snippet shows this in practice:

$NewVM = New-AzureVMConfig -Name $VMName -InstanceSize 'Basic_A2' -ImageName $2012R2imgs[0].ImageName |    Add-AzureProvisioningConfig -Windows -AdminUsername $admin -Password $myPwd -NoRDPEndpoint -NoWinRMEndpoint|    Set-AzureSubnet 'App-Net'

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like