Thursday, June 19, 2014

Setting up your PowerShell environment to manage your Microsoft Azure subscription.

The purpose of this blog post is to get someone new to Azure PowerShell up and going in little time.It will also be a quick reference for me as this is not something I do everyday and hence I have found myself doing the same research a few times. 

I will be walking you through setting up your workstation environment to use PowerShell to manage your Microsoft Azure environment. Please note that this is not the only way to do this but it is a quick way to get started. If you want to use your own security certificates you will have to follow some additional steps not covered here. 

Let's get started..

Installing the Windows Azure PowerShell Cmdlets


Download the Windows Azure PowerShell module from the Windows Azure Downloads page. On this page, you will find the Install link under the Windows Powershell section.

Download and execute the .exe file. After doing so, the Web Platform Installer comes up



Click next and take a moment to review the software prerequisites list. 



Click on I accept to proceed and start the installation. 

After the installation finishes you can close the web Platform Installer.

Establishing a secure connection between your PowerShell environment and Windows Azure

  • Open your preferred PowerShell scripting environment or the PowerShell command line. I'll use the PowerShell ISE in this example.
  • Set the execution policy setting to "Remote Signed" which by default sets the execution policy for the Local Computer as scope. see more_about_execution_policies for more details.
         PS C:\> Set-ExecutionPolicy RemoteSigned
  • Export the publishing settings from your Windows Azure subscription:

          From PowerShell Execute the Get-AzurePublishSettingsFile command. 


This command will open a browser window. If you are not already logged into the Windows Azure Portal you will be directed to the sign in page and after entering your credentials the save file window comes up. 

Take a note of the path and file name where you save the publishing settings file.




Please note that this method automatically generates management certificates for each subscription as shown below.  You can verify this by going to the "Settings" section in the Windows Azure management portal. You should now see all the Management Certificates associated with your subscriptions.



Alternatively to exporting your publishing settings, you can use the Set-AzureSubscription command to set up your subscriptions information and connection configuration. 


  • Execute the Import-AzurePublishSettingsFile command in PowerShell to import the publishing settings  into PowerShell by refferencing the publishing settings file downloaded in a prior step. The command should look like this: 
          Import-AzurePublishSettingsFile 'FilePath\PublishingFileName'


The command completes.

You can inspect the files created under %user%\AppData\Roaming\Windows Azure Powershell



Test your connection


Our last step is to verify we now have connectivity to our Windows Azure environment.

Execute the following PowerShell Command: Get-AzureSubscription


Verify that all the subscriptions for which you are an administrator are listed.

That's it. You are now ready to unleash the power of PowerShell and Microsoft Azure. Have fun!

Recommended Resources: