How To Schedule Azure VMs to Turn On and Off using Azure Automation

In this blog post, I will show you how to Start and Stop Azure Virtual machines automatically based on a daily schedule using an Azure Automation account.

Azure Automation

Using Azure Automation, we can schedule tasks that can manage our resources and save money at the same time.

In my Case I have a development virtual machine. I need to start every day for a few hours and then turn it off.

With Azure Automation I will create a solution that turns the Virtual machine on and off.

Get Started

To get started, I start by creating an Automation Account from the Azure Portal.

From the Add Automation Account, I need to name the account use an Active Subscription and Create Azure Run As account that will be used as the account that accesses the resource and starts and stop the VM.

Start / Stop VM Solution

For the Start and Stop operation, Azure has built in solution that we need to add and configure.

To add the solution, from the Automation Account menu click on Start/Stop VM

From Start/Stop VM Solutions page, click on Learn more about and enable the solution link to create a new solution.

Using the second option we can manage existing Start and Stop VM solutions.

Click Create to start the creation process

In the Add Solution page, we need to create a Log Analytics account first that will hold all the logs from the automation jobs that will allow us to review the jobs.

We also need to select the Automation account we created in the beginning of the post.

In the last option, we configure the VM or VMs that we need to stop and start every day.

Below are the Log Analytics screen and the settings I am using.

Select Virtual Machine

The configuration part is essential because if we misconfigure it we can stop the wrong VMs.

To select our VM, We first need to specify the Resource Group name and then exclude all the VMs we don’t want to be part of the stop/start operation and set the schedule for the VMs.

In the next screenshot, you can see my configuration.

Below, You can see my runbook configuration.

I selected the resource group with my VM and excluded all the VMs I don’t want to be part of the Start/Stop operation.

You can also see that I have set up the schedule and email notification.

Check Job

Once the job is configured, I can monitor it with other jobs from the Azure Automation page.

Conclusion and Notes

Azure Automation and Stop/Start VM solution is a great feature that can help you manage the cost of your Development and Test Virtual Machines by keeping them off while that is not in use.

Azure Automation comes with a free 500 minutes a month job run time and $0.002 per minute after.

In my next article, I will show you how to manage your automation account.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.