Integrate auto-shutdown configuration in ARM template deployments for Azure VMs

In November 2016 Microsoft introduced the auto-shutdown feature to Azure VMs which was originally available in Azure DevTest Labs.


The auto-shutdown feature can be simply enabled through the Azure portal after a VM is deployed.


If you are doing a lot of VM deployments, an Azure Resource Manager template is the way to go. Enabling and configuring the auto-shutdown feature through ARM templates is easy.

Just add the following lines to your ARM template for VM deployments and modify it appropriately. You should place the lines of code in the resources section of the VM resource.


"apiVersion": "[providers('Microsoft.DevTestLab','labs').apiVersions[0]]",
"type": "microsoft.devtestlab/schedules",
"name": "[concat('shutdown-computevm-',parameters('vmName'),copyIndex(parameters('numerationOfVMs')))]",
"location": "[resourceGroup().location]",
"dependsOn": [
"properties": {
"status": "Enabled",
"taskType": "ComputeVmShutdownTask",
"dailyRecurrence": {
"time": "1900"
"timeZoneId": "W. Europe Standard Time",
"notificationSettings": {
"status": "Disabled",
"timeInMinutes": 15
"targetResourceId": "[resourceId('Microsoft.Compute/virtualMachines',concat(parameters('vmName'),copyIndex(parameters('numerationOfVMs'))))]"

As you can see I am always using the latest API version. This approach is a bit risky, because things in the template can get broken quickly with an newly API version released on the Azure platform. So the latest API version right now is 2017-04-26-preview and this version works without any issues.

Beside the API version you also have to modify name, dependsOn and targetResourceId to get it running in your ARM template.

Name is the name of the resource as shown in the Azure portal or through API calls after the resource is successfully deployed.


Last but not least, we need dependsOn to specify the dependency on the VM. So the VM will be deployed first before we start the configuration. The targetResourceId directly links to the VM we would like to configure with the auto-shutdown feature.

Happy deploying!


Leave a Reply