In this tutorial, we’re going to learn how to Shutdown and Start cloud-based Microsoft Azure Virtual Machines on a schedule. The process takes about 1-2 minutes and is easily replicable to any and all VMs in your Azure subscription in just a few minutes more. It works for Windows and Linux VMs and does not rely on somewhat complex and hard to maintain PowerShell scripts or Azure Automation runbooks. Also, if any errors occur during either start or shutdown of VMs, you will get an immediate notification.
If you have production Azure VMs that need to remain up but are just utilized less, please learn more about how to scale down Azure VMs on a schedule.
Scheduling the start and shutdown of VMs allows you to save money on Azure costs. A VM that has been shutdown and deallocated does not incur any Azure charges (except for the space it occupies in blob storage). Shutting down VMs is usually beneficial for DEV/QA and other non-production environments, CI/build servers, or for production environments where access to VMs is required only during specific times.
You will need a Netreo account. Request a demo here. Netreo is a pretty sophisticated monitoring and automation software for Azure. By using Netreo, you’ll have access to a ton of useful performance metrics, logs, alerts, integrations, and other automation features. Many companies easily justify the relatively inexpensive cost of Netreo by configuring it to power-down their unused VMs.
However, if you want to shutdown and start Azure VMs on a true budget, you will want to learn about Azure Automation and Azure PowerShell. There are a few dozen blogs on this particular subject and we’ll link to them at the bottom of this article. Be aware, that you will still need to find ways to get alerted when Azure Automation Runbooks fail to run properly, otherwise you may end up with unpleasant surprises every once in a while.
Technical considerations to note: when a VM is shutdown its IP is deallocated. When it is brought back up, it will get a new IP unless it is assigned an Azure Reserved IP.
Ensure that your Azure Virtual Machines have been added to Netreo account. Simplest way to do so is to run thru the Netreo Setup Wizard. It takes a few minutes and it is very intuitive and straightforward.
After Wizard completes, edit the monitoring definition of a particular Azure VM and on the Actions tab and define two actions; one to stop and one to start a VM at specific times. In detail:
Configuring other VMs to shutdown and start on the same schedule is a fairly trivial task in Netreo.
There are a number of excellent blogs that provide detailed instructions on how to use Azure Automation Runbooks or Scheduling Manager with Azure PowerShell to automate startup and shutdown of VMs. Here are a links to a few of them