Azure VM start/stop schedule using Azure Automation

There are few runbook in gallery which helps to schedule shutdown and reboot of Azure VM but they no longer work or for Classic Azure. Microsoft has given a easy way to implement this without having to learn any scripts.

Although Microsoft document explains on how to set Start/Stop VM under automation account, it is little vague for me and i found some Admins struggling to follow it. So i thought i can try and make that simple

The most sorted scenario is to schedule a Azure vm shutdown and reboot during off business hours or weekends. So i’ve implemented that solution through Azure automation.

To Start/Stop VM automatically to save cost, you need

  • OMS workspace
  • Automation account

If you don’t have them already, you can create them on the way of creating this VM reboot schedule.

  • Login to your Azure portal
  • Search for Automation account, Click ADD
  • I’ve named it as Start-StopVM and I have choose UK South, Make sure you say ‘Yes’ to Create Azure Run As Account (this will avoid complications to your reboot process)
  • Under the automation account, Look for Start/Stop VM
  • Click on “Learn more about and enable the solution”

Once you choose to “Create”, you need to fill the following information.  If you don’t already have OMS workspace, then you need to create one.

  • Workspace – TestingShutdownRestartVM
  • Automation Account – Start-StopVM

Under configuration,

  • Target ResrouceGroup Names – *
  • VM Exclude List – None

Note:- The resource group and VM Exclude List can be setup here, but since we wanted to reboot one or group of VM, leave this as it is.

  • Schedule current date/time
  • Email functionality – if needed ‘Yes’ and email address to receive the alert
  • Click Create
  • Once you do that, you will see list of Runbooks added to the automation account,

This is the place where we are going to customize, the following things

  1. List of VM’s or VM needs to be rebooted
  2. Schedule in which the VM needs to be rebooted

Click SequencedStartStop_Parent runbook -> Click Schedule and Click ‘Add a Schedule’

Click Schedule – Create a new Schedule, (I’ve named it as Sequenced-StartVM and Sequenced-StopVM and used it already under the schedule).  You can customize the settings later if you want.  Choose recurring if you want the start to happen every week, month, hour or Day.

The following is the place where you define the action and list the vm or vm’s

  • Action                           – Start
  • WhatIF                          – $ture or $false ($true, if you are testing)
  • ContinueOnError      – $true
  • VMList                          – List the vm’s or vm (you can use , to add more than one VM)
  • Do the same thing again to Stop the VM. (I’ve named it as Sequenced-StartVM and Sequenced-StopVM and used it already under the schedule).

Note:- Remember this schedule is for “Runbook” not for Automation account. 

After you have finish configuring, it would like this under schedule.

Note:- The parameter cannot be changed after you schedule them.  The schedule can be changed.  If you’d like to remove/add/modify VM’s, you need to create a new schedule

My schedule is to stop the VM on Friday night 8:00 PM and Start the VM on Monday morning 8:00 AM

  • If you go to automation account -> Runbooks -> SequencedStartStop_Parent -> Jobs
  • You can go in to this log to find out what happened during the stop and start process.