Skip to content

Control Azure VMs with Powershell

Posted in Microsoft Azure

Like any physical or virtual server, Microsoft Azure VMs can be started, rebooted and shut down. You can do this through the Microsoft Windows Azure Management Portal, or through the new Microsoft Azure Portal.
But you can also control Azure VMs with your local PowerShell.

Requirements


Clearly, an Azure subscription and in addition you need the Azure Powershell Modul.
This then installed everything else is needed, for example the .NET framework.

Connect


Start your Powershell and import the Azure CmdLets.

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

Download the Azure Abonnement Certficate if you haven’t already one.
pre>Get-AzurePublishSettingsFile
An Azure website opens an the download starts. Save the file localy and open that path with your PowerShell.

Import that file in Powershell. Tip: use autocomplete with tabulator.

Import-AzurePublishSettingsFile 'PATH\SUB_NAME-DOWNLOAD_DATE-credentials.publishsettings'

Control Azure VMs with Powershell


With this CmdLet you get a list of VMs of the subscription.

Get-AzureVM | FT

Dies Zeigt euch die VM-Namen und die Service-Namen an. Beide braucht ihr für die weiteren Kommandos.
This shows you the names and service-names of your VMs. You need both information for further commands.
Start VM

Start-AzureVM -ServiceName YOURSERVICENAME -Name YOURVMNAME

Reboot VM

Restart-AzureVM -ServiceName YOURSERVICENAME -Name YOURVMNAME

Shuot down VM

Stop-AzureVM -ServiceName YOURSERVICENAME -Name YOURVMNAME–Force

This does completly shut down the VW, so that it it will not produce any costs.
VM löschen

Remove-AzureVM -ServiceName YOURSERVICENAME -Name YOURVMNAME –DeleteVHD

Caution: The VM and the hard drive are gone after that.

Summary


If you save the functions shown here in a script from, you can relatively quickly control Azure VMs with PowerShell so the check the status or high accordingly, shutdown or restart.
With the Azure Abonnement Zertifikat someone without access to the management portal can control the Azure VMs with Powershell.

You find the complete Azure Cmdlet Referenz at the MSDN and also examples how to create Azure VMs with Powershell.

Be First to Comment

Leave a Reply

Your email address will not be published.