Manage your Azure resources with PowerShell

Jan.27,2014

PowerShell is a great tool for automating simple tasks and also works with Windows Azure.
I personally use it to start and stop a Virtual Machine which I’m not using on a regular basis to save some money. By using these scripts I don’t have to login to the portal anymore to start and stop the VM. There are a lot of other usages for PowerShell and Azure, but I will get to that later.

Let’s start with setting up PowerShell and Azure (you only have to do this once). First you need to install Windows Azure PowerShell, by downloading it here.

The Web Platform Installer installs all dependencies for the Windows Azure PowerShell cmdlets. After installing you need to setup your Azure subscription so that it can be used to manage your services. You can do this by opening a PowerShell command prompt and type:Get-AzurePublishSettingsFile.

After hitting “enter” a browser window opens and (after you logged in) will prompt you to download the .publishsettings file.

Once saved, I used the Import-AzurePublishSettingsFile to imports the .publishsettings file for use by PowerShell. This file includes a management certificate that contains the security credentials.

Now you’re all set to manage your Azure resources from within PowerShell.

Here are some commands to get you started:
To view your Virtual Machines:Get-AzureVM

To start a VM:Start-AzureVM -Name “VMName” -ServiceName “ServiceName”

To stop a VM (The -Force will deallocate your VM, this status will not incur any compute costs.):Stop-AzureVM -Name “VMName” -ServiceName “ServiceName” -Force