Manage Azure IaaS with Windows PowerShell: Part 3

Doctor Scripto

Summary: Access some information you need to easily automate virtual machine creation in Azure.

Honorary Scripting Guy, Sean Kearney, is here to rain the Power of PowerShell and Azure down onto you!

   Note This is the third post in a series. You might also enjoy reading:

Yesterday we saw how to create storage in Azure. Today we're going to examine how to access some of the information you'll need to easily automate virtual machine creation in Azure.

Normally when I create a virtual machine (or any other resource in Azure), I will be asked for locations where the service is to be hosted. We noticed this in Part 1 when we looked at creating a virtual network within Azure.

Image of menu

We can see there were several locations worldwide where the service can be hosted. Rather than memorizing this information for a script, wouldn't it make sense that we should be able to pull it directly from Azure?

We can, of course. When you are connected to Azure, you have a cmdlet that will yield exactly that information: Get-AzureLocation. We will format the output as a table to make it more readable:

Image of command output

If we examine the members of this object, we can see each location is able to provide a certain set of services:

Image of command output

We can look at a location, such as East US, and use VirtualMachineRoleSizes to see what virtual machines are available in that location:

(Get-AzureLocation | Where { $_.DisplayName –eq 'East US'}).VirtualMachineRoleSizes

Image of command output

In addition, when we create virtual machines, there is a dynamically growing series of templates from Microsoft. We can also access this list directly from Azure by using the Get-AzureVMImage cmdlet. Here is a look at some partial output because this list is massive:

Image of command output

If we run a count on the total output, including public and MSDN images, there are 343 images available (including previous versions). That's a pretty impressive collection! We can filter on the operating system type, whether the image is an MSDN-only image, which locations it is available on, and even the label (which is where we will see the name).

Let's identify all the images with the name Windows Server 2012 R2 in the label:

Get-AzureVMImage | where { $_.Label –like ' Windows Server 2012 R2*' } | Select Label,OS

Image of command output

As we can see, there will be multiple versions of virtual machine templates (at least in an N-1 version count):

We can access the template list directly from Azure, in addition to the datacenter locations.

Knowing that this is programmatically accessible to us will make all of this much easier in our next step, creating virtual machines from a template in Azure by using Windows PowerShell cmdlets in Azure!

Stop by tomorrow to experience the amazing power to be unleashed from Azure with Windows PowerShell!

I invite you to follow The Scripting Guys on Twitter and Facebook. If you have any questions, send an email to The Scripting Guys at, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then remember eat your cmdlets every day with a dash of creativity.

Sean Kearney, Windows PowerShell MVP and Honorary Scripting Guy


Discussion is closed.

Feedback usabilla icon