22 out of 31 rated this helpful - Rate this topic

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:

Before you start using the Windows Azure cmdlets, make sure that you have the following:

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.

To install Windows Azure PowerShell:

  1. On the Downloads page, under Windows, click Install.

  2. When prompted to run or save the installation file, click Run.

  3. Click the checkbox to accept the license agreement, click Install, and then finish the wizard.

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:

  1. Click Start, click All Programs, click Windows Azure, right-click Windows Azure PowerShell, and then select Run as administrator.

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

    PS C:\> Set-ExecutionPolicy RemoteSigned
    
    noteNote
    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:

  1. Click Start, click All Programs, click Accessories, click Windows PowerShell, right-click Windows PowerShell, and then click Run as administrator.

    noteNote
    You only need to use Run as administrator to set the execution policy. Future Windows PowerShell sessions can be run as a standard user.

  2. In the Windows Azure PowerShell window, type the following command, press Enter, and then type Y to finish the command:

    PS C:\> Set-ExecutionPolicy RemoteSigned
    
  3. 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"
      

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:

  1. At the Windows PowerShell command prompt, type the following command, and then press Enter:

    PS C:\> Get-AzurePublishSettingsFile
    
    A browser window opens at https://windows.azure.com/download/publishprofile.aspx, where you can sign in to Windows Azure.

  2. 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.

  3. In the Windows Azure PowerShell window, run the following command:

    PS C:\> Import-AzurePublishSettingsFile <mysettings>.publishsettings
    
    Where <mysettings>.publishsettings is the file that you downloaded in the previous step.

    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

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

  1. Open a Windows Azure PowerShell command shell, or import the Windows Azure module into a Windows PowerShell window.

  2. 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
    
    noteNote
    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.

  3. 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
    
  4. 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"
    
    See Set-AzureSubscription for more details.

You can now use the Windows Azure cmdlets. For more information, see Use Windows Azure Cmdlets.

Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.
facebook page visit twitter rss feed newsletter