Auto shutdown Azure VMs

Making sure VMs not being used is critical to optimize Azure spend. Here are a few ways to shut them down automatically!

John Savill

December 28, 2016

1 Min Read
Auto shutdown Azure VMs

Q. Is there anything built in to Azure to automatically shutdown VMs at a certain time?

A. There are numerous solutions to automatically shutdown VMs:

  • Use an Azure Automation to shutdown whatever VMs are required and create a schedule to call the automation

  • Run a PowerShell script to scan for when VMs where shutdown by users (but still provisioned on the fabric and then shut them down (to stop paying) as I created at http://windowsitpro.com/azure/deprovision-vms-are-stopped-azure-after-20-minutes

  • Utilize the DevTestLabs schedule resource that will shutdown VMs at certain times with a configurable notification which is configured via JSON, e.g.:

{  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",  "contentVersion": "1.0.0.0",  "parameters": {    "vmName": {      "type": "string"    }  },  "variables": {    "policyName": "[concat('shutdown-computevm-', parameters('vmName'))]",    "vmResourceId": "[resourceId('Microsoft.Compute/virtualMachines', parameters('vmName'))]"  },  "resources": [    {      "apiVersion": "2016-05-15",      "type": "Microsoft.DevTestLab/schedules",      "name": "[variables('policyName')]",      "location": "[resourceGroup().location]",      "properties": {        "status":"Enabled",        "timeZoneId":"Central Standard Time",        "taskType":"ComputeVmShutdownTask",        "notificationSettings":{          "status":"Disabled",          "timeInMinutes":15,          "webhookUrl":null        },        "targetResourceId":"[variables('vmResourceId')]",        "dailyRecurrence":{          "time":"1800"        }      }    }  ],  "outputs": {  }}

 

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like