The auto start and stop of virtual machines in Azure through Automation Account is a useful way to automate virtual machines schedules which leads to resource optimization and cost. Mainly when you do not use your VMs all day long.
To help you in your VM auto-schedule through Azure Automation, we listed the 3 main steps to achieve:
1/ Add Automation Service
First of all, you can create a Resource Group, it is not mandatory but it is strongly recommended in order to keep things clean and structured.
To add an automation account (on a VM or a resource group), first, click on “Add” to add a new service. Then use the search bar to find “Automation”. The publisher is “Microsoft” and the category is “Developer tools”.
Create an Automation Account. Specify the settings and click Create to add automation account.
If it is the first automation you are creating, click on “Yes” for “Create Azure Run as Account”.
2/ Configure Runbooks
To configure the runbooks, you have to open the Automation account, and click on “Runbooks” in the submenu “Process Automation”.
NOTE: You can delete default published runbooks in you have ones.
After, click on “Browse Gallery”, located on the top menu.
Use the search bar to find and import the following runbooks:
- Start Azure V2 VMs (created by: Azure Automation Product Team)
- Stop Azure V2 VMs (created by: Azure Automation Product Team)
Name your runbooks
Edit and publish them(When imported, a Runbook is in the "New" state but in order to be invoked, they need to be in a "Published" state)
3/ Schedule the Runbook
Last but not least, the schedule of the runbook. To edit the runbook, click on the button called “Link to schedule”.
By clicking on “Schedule” you will create a new schedule and specify the settings to apply. A menu will appear on the right with different settings to define.
NOTE: The process is the same to plan VM auto stop.
When your runbook is scheduled, click on “Start” to set live the runbook. Specify the following parameters and click Ok:
RESOURCEGROUPNAME: Specify the name of the resource group where the VM resides.
VMNAME: Specify the name of the VM that you would like to start or stop.
The runbooks are ready and will apply your start and stop planning on the selected VMs.