Main menu

Post navigation

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:

Installation

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

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 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:

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:

Automated configuration using Get-AzurePublishSettingsFile and Import-AzurePublishSettingsFile

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:

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):