Compartilhar via


Manage your Windows Azure with PowerShell

 

Recently, I’m getting a lot of questions about automated scripting capabilities of Windows Azure. Although you can manage your cloud services with Windows Azure Management Portal a lot of scenarios may benefit from advanced scripting features to save time.

Actually it’s really easy to start managing your Windows Azure Subscription with PowerShell. Assuming that you already have a Windows Azure account to manage just follow the steps below

 

1. You need to go download & install Windows Azure PowerShell cmdlets from Management Downloads page : https://www.windowsazure.com/en-us/manage/downloads/

image

 

2. Start your Windows Azure PowerShell window and set your ExecutionPolicy to RemoteSigned (you’ll require to run Windows Azure PowerShell as a Administrator to set ExecutionPolicy)

 

 PS C:\> Set-ExecutionPolicy RemoteSigned

If you want to work with Windows PowerShell ISE (which I really like), you may need to import Windows Azure PowerShell module.

 Import-Module 'C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\Azure.psd1'

 

3. Create a Management Certificate for Windows Azure, start your Visual Studio 012 Developer Command Prompt or Visual Studio 2010 Command Prompt as a administrator and run the command below by updating <CertificateName>. You’ll have your X.509 v3 certificate with a 2048 bits key length.

 

 makecert -sky exchange -r -n "CN=<CertificateName>" -pe 
 -a sha1 -len 2048 -ss My "<CertificateName>.cer"

4. Login to your Windows Azure Management Portal and upload this certificate to Settings > Management Certificates section.

5. Switch to Windows Azure PowerShell Windows download Windows Azure Publish Settings File by running the code below. A browser windows will open https://windows.azure.com/download/publishprofile.aspx and where you can sign in to Windows Azure and download publish settings file.

 PS C:\> Get-AzurePublishSettingsFile

6. And finally, Import your Publish Settings File by running the command updating <mysettings> with your file name.

 PS C:\> Import-AzurePublishSettingsFile <mysettings>.publishsettings

 

And that’s all, it’s pretty easy to start managing your Windows Azure subscription with PowerShell.

 PS C:\> Get-AzureSubscription

Plese note that your management certificate and publish settings file contains sensitive information for managing your service.

You should delete your Publish Settings file after importing and keep your .cer file in a secure location after uploading.

You can reach to Windows Azure Cmdlet Reference at https://msdn.microsoft.com/en-us/library/windowsazure/jj554330.aspx including Windows Azure Management Cmdlets and Windows Azure SQL Database Cmdlets.

 

Your environment is ready you can start using Windows Azure PowerShell :

You can view, configure, add or delete subscriptions, deployments, databases, virtual machines. You can also create Scheduled Tasks to run your management scripts.