Windows Azure is Microsoft`s 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 API`s 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:
- Virtual Machines
- Virtual Networks
- Storage Accounts
- Cloud Services
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:
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:
Get-Command -Module azure
There is also an overview of the currently available cmdlets on the Windows Azure Management Cmdlets website.
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:
1: Set-AzureSubscription `
2: -SubscriptionId 26e6d24e-7e46-4a30-9f58-a14706bbfea1 `
3: -Certificate (Get-ChildItem cert:\currentuser\my\8A15ED234D550ECBEDB7E051C59820105BFC2BEC) `
4: -SubscriptionName "Windows Azure MSDN – Visual Studio Ultimate"
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:
Get-AzureSubscription | Set-AzureSubscription -CurrentStorageAccount portalvhdspd3kt2t
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:
Get-Command -Module azure -Verb Get
For example, start with the Get-AzureVMImage cmdlet to obtain information about the available virtual machine images:
Get-AzureVM will list your virtual machines:
Start a virtual machine:
A few examples of typical usage:
1: # Create a new virtual machine
2: New-AzureVMConfig -Name "DEMO-01" -InstanceSize ExtraSmall -ImageName (Get-AzureVMImage).ImageName `
3: | Add-AzureProvisioningConfig –Windows –Password "P@ssw0rd" `
4: | New-AzureVM –ServiceName "DEMO-01" -Location "West Europe" -VNetName "Azure Vnet 01" -AffinityGroup 1
6: # Start the new virtual machine
7: Get-AzureVM "DEMO-01" | Start-AzureVM
9: # Connect to the new virtual machine using Remote Desktop
10: Get-AzureRemoteDesktopFile -ServiceName "DEMO-01" -Name "DEMO-01" –Launch
12: # Save your virtual network configuration to an XML-file
13: Get-AzureVNetConfig | Select-Object -Expand XMLConfiguration | Out-File c:\temp\Azure-Vnet.xml
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):
1: # Add an endpoint for PowerShell Remoting (Windows Remote Management)
2: Get-AzureVM "DC-AZURE-01" | Add-AzureEndpoint -Name "WinRM" -PublicPort 5985 -LocalPort 5985 -Protocol tcp | Update-AzureVM
4: # Add the hostname of the virtual machine to the local WSMan Trusted Hosts
5: Set-Item WSMan:\localhost\Client\TrustedHosts -Value "demo-01.cloudapp.net"
7: # Connect to the virtual machine using PowerShell Remoting
8: Enter-PSSession -ComputerName demo-01.cloudapp.net -Credential (Get-Credential)
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:
There are also several PowerShell related labs in the training kit, for example Automating VM Management with PowerShell, and Deploying Active Directory with PowerShell.
Trivia: This WordPress blog is hosted on Windows Azure Web Sites.