Using the Windows Azure Platform PowerShell Cmdlets

Exclusive offer: get 50% off this eBook here
Microsoft Windows Azure Development Cookbook

Microsoft Windows Azure Development Cookbook — Save 50%

Over 80 advanced recipes for developing scalable services with the Windows Azure platform with this Microsoft Azure book and eBook

$29.99    $15.00
by Neil Mackenzie | August 2011 | Cookbooks Enterprise Articles Microsoft

The Windows Azure Platform PowerShell cmdlets use the Windows Azure Service Management REST API to expose service management operations as PowerShell cmdlets. The cmdlets provide a convenient way to manage hosted services, including retrieving the properties of current deployments and uploading new and upgraded deployments.

In this article by Neil Mackenzie, author of Microsoft Windows Azure Development Cookbook, we will learn how to use the Windows Azure Platform PowerShell cmdlets to invoke various service operations in the Windows Azure Service Management REST API.

 

Microsoft Windows Azure Development Cookbook

Microsoft Windows Azure Development Cookbook

Over 80 advanced recipes for developing scalable services with the Windows Azure platform

        Read more about this book      

(For more resources on this subject, see here.)

Getting ready

If necessary, we can download PowerShell 2 from the Microsoft download center at the following URL:

http://www.microsoft.com/download/en/details.aspx?id=11829

We need to download and install the Windows Azure Platform PowerShell cmdlets. The package with the cmdlets can be downloaded from the following URL:

http://wappowershell.codeplex.com/

Once the package has been downloaded, the cmdlets need to be built and installed. The installed package contains a StartHere file explaining the process.

How to do it...

We are going to use the Windows Azure Platform cmdlets to retrieve various properties of a Windows Azure subscription and a hosted service in it.

  1. Create a PowerShell script named Get-Properties.ps1 and insert the following text:

    $subscriptionId = 'SUBSCRIPTION_ID'
    $serviceName = 'SERVICE_NAME'
    $thumbprint = 'THUMBPRINT'
    $getCertificate = Get-Item cert:\LocalMachine\My\$thumbprint

    Add-PSSnapin AzureManagementToolsSnapIn

    Get-HostedServices -SubscriptionId $subscriptionId
    -Certificate $getCertificate
    Get-AffinityGroups -SubscriptionId $subscriptionId
    -Certificate $getCertificate
    Get-HostedProperties -SubscriptionId $subscriptionId
    -Certificate $getCertificate -ServiceName $serviceName

  2. Launch PowerShell.
  3. Navigate to the directory containing Get-Properties.ps1.
  4. Invoke the cmdlets to retrieve the properties:

    .\Get-Properties.ps1

How it works...

In step 1, we create the PowerShell script to invoke the get hosted service properties, list affinity groups, and get hosted service properties operations in the Windows Azure Service Management REST API. We need to provide the subscription ID for the Windows Azure subscription, the name of the hosted service, and the thumbprint for a management certificate uploaded to the Windows Azure subscription. In the script, we retrieve the X.509 certificate from the Personal (My) certificate store on the local machine level. If necessary, we can specify the current user level, instead of the local machine level, by using CurrentUser in place of LocalMachine when we define $getCertificate.

In steps 2 and 3, we set up PowerShell.

In step 4, we invoke the script using a .\ syntax to demonstrate that we really want to invoke an unsigned script in the current directory.

There's more...

PowerShell supports an execution policy to restrict the PowerShell scripts that can be run on a system. If the current execution policy does not permit the Windows Azure Service Management cmdlets to run, then the execution policy can be changed to remote signed by invoking the following at the command prompt:

C:\Users\Administrator>PowerShell -command "Set-ExecutionPolicy
RemoteSigned"

This sets the global PowerShell execution context. PowerShell 2 introduced a command-line switch allowing it to be set only for the current invocation:

C:\Users\Administrator>PowerShell -ExecutionPolicy RemoteSigned

Azure Management cmdlets

Cerebrata has released a commercial set of Azure Management cmdlets that are more extensive than the Windows Azure Service Management cmdlets. The following PowerShell script retrieves the list of affinity groups for a Windows Azure subscription, including the GUID identifier not available on the Windows Azure Portal:

$subscriptionId = 'SUBSCRIPTION_ID'
$thumbprint = 'THUMBPRINT'
$getCertificate = Get-ChildItem
-path cert:\LocalMachine\My\$thumbprint

Add-PSSnapin AzureManagementCmdletsSnapIn

Get-AffinityGroup -SubscriptionId $subscriptionId
-Certificate $getCertificate

We need to provide the subscription ID for the Windows Azure subscription, and the thumbprint for a management certificate uploaded to the Windows Azure subscription. In the script, we retrieve the X.509 certificate from the Personal (My) certificate store on the local machine level. If necessary, we can specify the current user level, instead of the local machine lever, by using CurrentUser in place of LocalMachine when we define $getCertificate.

We can use the following command to retrieve the list of Windows Azure locations:

Get-AzureDataCenterLocation -SubscriptionId $subscriptionId
-Certificate $getCertificate

Summary

In this article we saw how to use the Windows Azure Platform PowerShell cmdlets to invoke various service operations in the Windows Azure Service Management REST API.


Further resources on this subject:


Microsoft Windows Azure Development Cookbook Over 80 advanced recipes for developing scalable services with the Windows Azure platform with this Microsoft Azure book and eBook
Published: August 2011
eBook Price: $29.99
Book Price: $49.99
See more
Select your format and quantity:

About the Author :


Neil Mackenzie

Neil Mackenzie has worked with computers for nearly three decades. He started his computer career doing large-scale numerical simulations for scientific research and business planning. Since then, he has been involved primarily in healthcare software, developing electronic medical records systems. He has been using Windows Azure since PDC 2008 and has used nearly all parts of the Windows Azure platform – including those that no longer exist. Neil is very active in the online Windows Azure community – in particular, helping to solve many of the questions raised in the MSDN Windows Azure Forums. He is a Microsoft MVP for Windows Azure.

Books From Packt


Microsoft SQL Azure Enterprise Application Development
Microsoft SQL Azure Enterprise Application Development

Getting Started with Microsoft Application Virtualization 4.6
Getting Started with Microsoft Application Virtualization 4.6

Microsoft Azure: Enterprise Application Development
Microsoft Azure: Enterprise Application Development

Applied Architecture Patterns on the Microsoft Platform
Applied Architecture Patterns on the Microsoft Platform

Microsoft Windows Communication Foundation 4.0 Cookbook for Developing SOA Applications
Microsoft Windows Communication Foundation 4.0 Cookbook for Developing SOA Applications

Microsoft Silverlight 4 and Windows Azure Enterprise Integration: RAW
Microsoft Silverlight 4 and Windows Azure Enterprise Integration: RAW

Microsoft SharePoint 2010 and Windows PowerShell 2.0: Expert Cookbook
Microsoft SharePoint 2010 and Windows PowerShell 2.0: Expert Cookbook

Least Privilege Security for Windows 7, Vista and XP
Least Privilege Security for Windows 7, Vista and XP


No votes yet

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
d
k
g
n
Z
5
Enter the code without spaces and pay attention to upper/lower case.
Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software