Introduction

Whenever we turn on Azure VM it turn on time cost us, so it is best practice to turn on azure virtual machine only the specific time duration, when we are working on. Generally we start and stop azure virtual machine by using Azure management portal, which required rapidly login and follow some required steps. We can also do this process by using PowerShell that save our time because it not required every time to login into management portal and follow some steps. We can also perform automation by using these PowerShell commands.

Steps to start and stop Azure Virtual machine:

Login Azure account on PowerShell

Before performing our action with PowerShell, first we have to add our Azure account in PowerShell. Execute the following command for it.

Type Add-AzureAccount command in PowerShell, a window will open, enter your email address here which has the subscription.

command

email

Get the subscriptions details

Get the current Subscription

Get the current subscription id:

(Get-AzureSubscription -Current).SubscriptionId

Set current Subscription

If you have more than one subscription, and your current subscription is different from your required subscription, then set your desire subscription as current subscription:

List all virtual machine in current Subscription:

Get-AzureVM

It will display all VMs with service name and VM name. Please check VM which you want to migrate should exist here.

AzureVM

Start Azure VM

Start-AzureVM-ServiceName "anmolwin8vs" -Name "anmolwin8vs"

anmolwin8vs is my respective Azure cloud service and VM name.

Stop Azure VM

Stop-AzureVM -ServiceName "anmolwin8vs" -Name "anmolwin8vs"

Start Windows Azure Virtual Machines on a Schedule.

Stop Windows Azure Virtual Machines on a Schedule

Please note, on schedule script will work only on Windows Server 2012 R2 and Windows 8.1 version.