Retrieve the Latest Windows Azure VM Image Name

When we want to create a new Microsoft Azure VM using PowerShell, we need to specify the OS image.

The ImageName parameter is required by New-AzureVMConfig and New-AzureQuickVM cmdlets.

To get a list of all available images, we use the Get-AzureVMImage cmdlet.

This command will return a list of all images and details for each of them.

We can filter the results.

For example: if we want to get the list of all Windows Server 2012 R2 Datacenter images, we can use the following command:

Get-AzureVMImage | where { $_.ImageFamily -eq "Windows Server 2012 R2 Datacenter"}

This command still return several images.

If we want to use list just the last image released we order the images by the PublishedDate property and get the first item of the list.

(Get-AzureVMImage | where { $_.ImageFamily -eq "Windows Server 2012 R2 Datacenter"} |Sort-Object -Descending -Property PublishedDate)[0].ImageName


Add comment