The Case of the Latest Windows Azure VM Image

When creating new Windows Azure VMs, an Operating System (OS) image needs to be specified.  Microsoft maintains a repository of images that are available to be used when creating a new VM.  These images could be regular Windows Server 2012 or Windows Server 2008 images, server images with software like SQL Server or BizTalk server installed, or even various Linux distributions.

To get a list of all available images, execute the Get-AzureVMImage cmdlet.  This will return a list of all possible images and details for each.

get-azurevmimage

Sometimes there may be multiple versions of a particular type of image.  For example, Microsoft will maintain a few versions of Window Server images – these very by patch level.

Notice the properties available (Location, Label, OS, ImageFamily, etc.) for each image.  These can be very helpful in narrowing the list of images.

Find the Image Type

In order to find a particular type of image, the ImageFamily property can be used.


Get-AzureVMImage `
| where { $_.ImageFamily -eq “Windows Server 2012 Datacenter” }

This returns details of only the Windows Server 2012 Datacenter images.

get-azurevmimage - imagefamily

Find the Latest Image

In order to find the most recent version of a particular type of image, the PublishDate property can be used to enhance the query.


$images = Get-AzureVMImage `
| where { $_.ImageFamily -eq “Windows Server 2012 Datacenter” } `
| Sort-Object -Descending -Property PublishedDate

$latestImage = $images[0]
$latestImage

Using the above snippet, only the most recent version of the “Windows Server 2012 Datacenter” image will be returned.

Images Aren’t Always Available

Take another look at the properties returned by Get-AzureVMImage.  Notice there is a Location property.  This specifies in which Windows Azure data centers the particular image is available.  All images may not be available in all data centers.  I’ve only seen this happen a few times, and it seemed to be related to a new OS image rolling out to the various data centers.  If trying to create a new VM with an image that is not supported in the target data center, the Windows Azure service management interface will return a 400 error related to a location constraint:

New-AzureVM : “An exception occurred when calling the ServiceManagement API. HTTP Status Code: 400. Service
Management Error Code: BadRequest. Message: The location constraint is not valid. Operation Tracking ID:
0ba6c633f3xxxxxxxxxxxxxxxxxxxxxx.”

To remedy this, slightly modify the script to include logic to select images that are only available in the desired data center location.


$images = Get-AzureVMImage `
| where { $_.ImageFamily -eq "Windows Server 2012 Datacenter" } `
	| where { $_.Location.Split(";") -contains "West US"} `
	| Sort-Object -Descending -Property PublishedDate

Using the above snippet, only the most recent version of the “Windows Server 2012 Datacenter” image that is supported in the “West US” datacenter will be returned.

Create the Virtual Machine

Now that the desired VM OS image has been found, the New-AzureVMConfig and New-AzureVM cmdlets can be used to create the new Virtual Machine.


# Get the latest version of the Windows Server 2012 Datacenter image.
$images = Get-AzureVMImage `
| where { $_.ImageFamily -eq $imageFamily } `
	| where { $_.Location.Split(";") -contains $location} `
	| Sort-Object -Descending -Property PublishedDate
$myVM = New-AzureVMConfig -Name “myvm01” -InstanceSize “Small” -ImageName $images[0].ImageName -DiskLabel "OS" `
| Add-AzureProvisioningConfig -Windows -Password $password -AdminUsername $username -DisableAutomaticUpdates

New-AzureVM -ServiceName “myvmservice” -VMs $myVM -Location “West US” -WaitForBoot

About these ads
Tagged with: ,
Posted in PowerShell, Windows Azure
One comment on “The Case of the Latest Windows Azure VM Image
  1. […] The Case of the Latest Windows Azure VM Image (posted July 30) […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow Michael S. Collier's Blog on WordPress.com
Follow

Get every new post delivered to your Inbox.

Join 1,709 other followers

%d bloggers like this: