Get Started with Windows Azure Cmdlets
Updated: October 29, 2012
To get started with the Windows Azure module for Windows PowerShell, you’ll need to:
Prepare your work environment
Install the Windows Azure module for Windows PowerShell
Configure connectivity between Windows Azure and your workstation
Before you start using the Windows Azure cmdlets, make sure that you have the following:
A computer that is running Windows 8, Windows 7, Windows Server 2012, or Windows Server 2008 R2.
A Windows Azure subscription. For more information about subscriptions, see Purchase Options, Member Offers, or Free Trial.
An uploaded management certificate. For more information about how to create and upload a management certificate, see How to: Manage Management Certificates in Windows Azure.
Install the Windows Azure module and then set the Windows PowerShell execution policy. You can either run cmdlets by using the Windows Azure PowerShell command shell or by importing the Windows Azure cmdlets directly into Windows PowerShell.
The Windows PowerShell execution policy determines the conditions under which configuration files and scripts are run. The Windows Azure PowerShell cmdlets need the execution policy set to a value of RemoteSigned, Unrestricted, or Bypass. For more information on the execution policies, see About_Execution_Policies.
When you install the Windows Azure module, the Windows Azure PowerShell command shell is also installed.
To use the Windows Azure PowerShell command shell:
Click Start, click All Programs, click Windows Azure, right-click Windows Azure PowerShell, and then select Run as administrator.
If this is the first time you have run the Windows Azure PowerShell command shell, run the following command, and type Y to finish the command:
Note You only need to use Run as administrator to set the execution policy. Future sessions can be run as a standard user. Because the Windows Azure PowerShell command shell is a 32-bit command shell, and execution policy is set separately for 32-bit and 64-bit shells, you must also set the execution policy for 64-bit Windows PowerShell to use the Windows Azure module in it.
If you’d rather integrate the Windows Azure cmdlet module into Windows PowerShell, you can easily import it.
To import the Windows Azure cmdlet module into Windows PowerShell, first set the execution policy:
Click Start, click All Programs, click Accessories, click Windows PowerShell, right-click Windows PowerShell, and then click Run as administrator.
Note You only need to use Run as administrator to set the execution policy. Future Windows PowerShell sessions can be run as a standard user.
In the Windows Azure PowerShell window, type the following command, press Enter, and then type Y to finish the command:
Type one of the following commands and then press Enter:
On a 64-bit version of the operating system, type:
PS C:\> Import-Module "C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\Azure.psd1"
On a 32-bit version of the operating system, type:
PS C:\> Import-Module "C:\Program Files\Microsoft SDKs\Windows Azure\PowerShell\Azure\Azure.psd1"
- On a 64-bit version of the operating system, type:
Before you start using the Windows Azure cmdlets to automate deployments, you must configure connectivity between your workstation and Windows Azure. This can be done manually by configuring the management certificate and subscription details with the Set-AzureSubscription and Select-AzureSubscription cmdlets, or automatically by downloading the PublishSettings file from Windows Azure and importing it. The settings for Windows Azure PowerShell are stored in: <user>\AppData\Roaming\Windows Azure PowerShell. The PublishSettings file method works well when you are responsible for a limited number of subscriptions, but it adds a certificate to any subscription that you are an administrator or co-administrator for. In complex or shared development environments, it might be desirable to manually configure the publish settings and subscription information, including any management certificates, for your Windows Azure subscriptions.
The Windows Azure module includes the PublishSettingsFile cmdlets that simplify setting up your Windows PowerShell environment for use with Windows Azure. Complete the following steps to prepare for deploying and managing applications:
At the Windows PowerShell command prompt, type the following command, and then press Enter:
PS C:\> Get-AzurePublishSettingsFile
Sign in to the Windows Azure Management Portal, and then follow the instructions to download your Windows Azure publishing settings. Use your browser to save the file as a .publishsettings file to your local computer. Note the location of the file.
In the Windows Azure PowerShell window, run the following command:
PS C:\> Import-AzurePublishSettingsFile <mysettings>.publishsettings
You should delete the publishing profile that you downloaded after you import those settings. The downloaded profile contains a management certificate that should not be accessed by unauthorized users.
To manually configure the publish settings and subscription information, you'll need to obtain and upload a management certificate to the Windows Azure subscription you want to manage. For details on management certificates in Windows Azure, see: How to: Manage Management Certificates in Windows Azure.
To configure your Windows Azure PowerShell settings, you'll need:
The name of the Windows Azure subscription you want to manage
The subscription ID of the Windows Azure subscription you want to manage
The thumbprint of your Windows Azure management certificate
|This information is available from the Settings window of the Windows Azure management portal.|
Complete the following steps to configure the settings to use the Windows Azure module:
Open a Windows Azure PowerShell command shell, or import the Windows Azure module into a Windows PowerShell window.
Run the following commands:
PS C:\> $mySubID = "<subscritionID>" PS C:\> $certThumbprint = "<Thumbprint>" PS C:\> $myCert = Get-Item cert:\CurrentUser\My\$certThumbprint PS C:\> $mySubName = "<SubscriptionName>" PS C:\> Set-AzureSubscription -SubscriptionName $mySubName -Certificate $myCert -SubscriptionID $mySubID PS C:\> Select-AzureSubscription -SubscriptionName $mySubName
Note If the Get-Item command fails because the path or item was not found, verify that the certificate is located in the specified store. (Open Certmgr.msc and navigate to the Personal Certificates folder, or use Windows PowerShell to go to the cert: drive and then use the Dir command to view the contents of the store.) If the certificate is missing, you can use Certmgr.msc to import it from the same .cer file you used to upload the management certificate. Then, retry the Get-Item command.
You can now connect to your Windows Azure subscription and manage it. To see the details of your Windows Azure subscription, type:
PS C:\> Get-AzureSubscription
To configure a default Windows Azure subscription, set a default storage account, or a custom Windows Azure service endpoint, use the Set-AzureSubscription cmdlet. For example, to set the current storage account to myuniquestore01 for $mySubName, type:
PS C:\> Set-AzureSubscription -SubscriptionName $mySubName -CurrentStorageAccount "myuniquestore01"
You can now use the Windows Azure cmdlets. For more information, see Use Windows Azure Cmdlets.