Azure Automation: How to easily schedule ARM VMs automatic start/shutdown

This blog post shows the steps how to easily schedule Start/stop your ARM VMs.
For example on demo/dev environments you can save costs when turning VMs off when you are not using them.

I will show you the easiest way and therefore I will do everything from the portal without needing any scripting knowledge.
We are going to use Graphical Runbooks which are provided by Microsoft. With these Runbooks you are able to schedule start/stop ARM VMs for Azure subscription or resource group or a single named VM.
In this example I have already create Resource Group called Demo and it contains one VM.

 

First we need to create Azure Active Directory user which we are using for automation:
Start Active Directory
automation001

This will forward you to Classic portal
Add user
automation002

Add account infromation
automation003

Select User Role and do not enable MFA
automation004

Get your temporary password

automation005automation006

Next we need to allow this Azure Active Directory user to manage this Azure subscription
automation007

And last we need to change temporary password. There are few steps you need to do:
1. Log out of Azure.
2. Log in to Azure as the Azure Active Directory user you just created, using full username (including part after @ symbol) and temporary password.
3. You will now be prompted to change the user’s password.

Next we will create Azure Automation Account
Select Automation Accounts
automation008

Add
automation009

Add your Automation Account name and select Resource Group
automation010

automation011

Next we need to add Assets:
automation012

As we are going to use Microsoft Graphic Runbooks we need to have Automation credential asset called AzureCredential that contains the Azure AD user credential with authorization for this subscription and Automation variable asset called AzureSubscriptionId that contains the GUID for this Azure subscription.

First we add Credential

automation013automation014

automation015

and then we need to add variable which contain our Azure Subscription ID
automation016
automation017

automation018

Now we have all needed Assets.
Next we select Runbooks and import needed Runbooks from the gallery
automation019automation020

Select Start Azure ARM VMs

automation021Import
automation022

automation023

Now repeat following steps for Stop Azure ARM VMs
automation024

Now we have two different Runbooks imported. Click StartAzureRMVM
automation025

Select edit
automation026

In my test case I´m using Resource Group called Demo which contain one VM so I need to add my Resource Group as default parameter of both Runbooks.
Select Input and Output
automation027

I´m adding Custom value of ResourceGroupName which contain my Resource Group name
automation028

After modification we need to publish Runbook
automation029

Now repeat following steps for StopAzureRMVM (add custom value to ResourceGroupName and publish Runbook).

Now we can schedule Runbooks run as we like. For example start every morning at 07.00am and shutdown every evening at 10.00pm.
Scheduling StartAzureRMVM
automation030

automation031

And then StopAzureRMVM

automation032automation033

That´s it, happy scheduling!

Leave a Reply

Your email address will not be published. Required fields are marked *