Managing Windows Azure using Windows PowerShell

Windows Azure is Microsofts platform for cloud computing, offering services such as databases, virtual machines and web sites. After being announced in 2008 and commercially available in 2010, the platform was primarily of interest for developers. In June 2012 Virtual Machines for Windows and Linux was announced, making the service more interesting for IT Professionals as well.

Windows Azure Virtual Machines

The first offering for running virtual machines in Windows Azure was the VM Role, targeted at scale-out cloud services. This offering made it possible to upload your own Windows Server 2008 R2 VHD image, which could be managed using Remote Desktop. The main disadvantage with this service from an IT Professionals perspective is that the service uses non-persistent storage.

The new Virtual Machines offering, currently available in Preview, brings more features which makes it more attractive for IT Professionals. The main differences compared to the VM Role is persistent storage, and more networking features. This means you can configure your own networks as well as a VPN tunnel to your on-premises network in Windows Azure Virtual Machines. This makes the offering attractive for many scenarios, such as:

  • Using Windows Azure as a secondary site
  • Deploying services typically deployed in a traditional DMZ, such as scale-out web servers
  • Lab and demo environments

Windows Azure PowerShell Cmdlets

There are several APIs available to automate Windows Azure administration. Targeted mainly at developer there is a Windows Azure REST API. For IT Professionals there are Windows Azure PowerShell Cmdlets available. The first PowerShell Cmdlets for managing Windows Azure was available on Codeplex, while the currently available cmdlets is available directly from the engineering team. The cmdlets is available as a Windows PowerShell module, and requires Windows PowerShell 2.0 or 3.0. Features which can be managed from the module includes:

  • Subscriptions
  • Virtual Machines
  • Virtual Networks
  • Storage Accounts
  • Cloud Services

Installation

The steps to download, install and configure your computer for the Windows Azure PowerShell Cmdlets is well documented on the Get Started with Windows Azure Cmdlets website.

The download link points directly to the Windows Azure PowerShell application available in the Web Platform Installer:

image

The installer will add the path (C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\) to the Azure PowerShell module to the $env:PSModulePath environment variable, which means you can import the module using the module name:

If you are using Windows PowerShell 3.0, you can skip the manual module import, due to the new module autoloading feature.

If you have not enabled execution of PowerShell scripts on your computer, you would need to configure your PowerShell execution policy before importing the Azure PowerShell module. A general recommendation is to use RemoteSigned:

To explore the available cmdlets, we can use Get-Command:

There is also an overview of the currently available cmdlets on the Windows Azure Management Cmdlets website.

Configuration

Before you can use any of the cmdlets to manage your Azure subscription, you must configure the publish settings and subscription information for your Windows Azure subscription. There are two ways to accomplish this:

  1. Automated configuration using Get-AzurePublishSettingsFile and Import-AzurePublishSettingsFile
  2. Manual configuration using Set-AzureSubscription and Select-AzureSubscription

#1 is the easiest one, you first run Get-AzurePublishSettingsFile which opens your default web browser where you have to sign-in to Windows Azure in order to download your settings file. When you have downloaded the file you use Import-AzurePublishSettingsFile and specify the path to the .publishsettings file you downloaded.

#2 requires more work, but is appropriate if you want more control over the settings. For example you may want to use your own certificate which you have uploaded to the Windows Azure Management Certificates store. This is a sample on how to use Set-AzureSubscription:

Now you should be able to use Get-AzureSubscription to see the details of the subscription you have configured. If you have configured more than one subscription, you can switch between the subscriptions using Select-AzureSubscription.

One last thing you might want to configure is a default storage account. Several cmdlets requires you to specify a storage account, which you will not need to do if you have configured a default account. To list the available storage accounts, run Get-AzureStorageAccount. To configure a default account, use Set-AzureSubscription with the CurrentStorageAccount parameter. An example:

 

Usage

Now that you have installed and configured your environment for Windows Azure PowerShell cmdlets, you are ready to use them.

I would recommend you to start exploring what is available by using the Get- cmdlets. You can obtain all of the Azure Get- cmdlets by using Get-Command:

 

For example, start with the Get-AzureVMImage cmdlet to obtain information about the available virtual machine images:

image

Get-AzureVM will list your virtual machines:

image

Start a virtual machine:

image

A few examples of typical usage:

When you create a new virtual machine, by default an endpoint for Remote Desktop will be created. If you do not want this default endpoint to be created, you can specify the switch parameter –NoRDPEndpoint on the Add-AzureProvisioningConfig cmdlet.

You can also create your own endpoints, for example for PowerShell Remoting (TCP 5985):

 

You can find more information on how to use the cmdlets on the  Use Windows Azure Cmdlets website.

I would also recommend you to download the Windows Azure Training Kit, which contains demos, labs and presentations. I would like to highlight the following presentations:

  • WindowsAzureITProOverview.pptx
  • WindowsAzureVirtualMachines.pptx
  • ManagingVMs-PowerShell.pptx

There are also several PowerShell related labs in the training kit, for example Automating VM Management with PowerShell, and Deploying Active Directory with PowerShell.

Resources

Windows Azure Virtual Machines

Windows Azure PowerShell

Windows Azure Management Portal

Windows Azure Training Kit

Sign up for a Windows Azure 90 day free trial

Trivia: This WordPress blog is hosted on Windows Azure Web Sites.