Azure virtual machine auto shutdown

This Azure tutorial will discuss the Azure virtual machine auto-shutdown option.

We can set the Azure virtual machine auto shutdown option in the Azure portal.

Azure virtual machine auto-shutdown

Follow the below steps to enable the Azure VM auto-shutdown option.

1. Login to https://portal.azure.com/.

2. Search for Virtual machines.

az vm auto-shutdown

3. You will see the list of VMs created in your Azure subscription. It will show the VM name, Type, Status, ResourceGroup, Location, etc.

azure vm auto shutdown powershell

4. Now click on the VM name. “MyNewVM” in my case. You can see the details of your virtual machine like Public IP address, status, Computer name, Operating system, Size, etc.

azure virtual machine auto shutdown

5. Now, from the left menu, select the “Auto-shutdown” option under the Operations section.

azure vm auto shutdown

6. Now fill in the options below

  • Enabled option as On
  • Scheduled shutdown: Mention the time when you want your VM to shut down in the Scheduled shutdown option automatically,
  • Time zone: Specify your time zone based on the country you belong to.
  • Send notification before auto-shutdown?: Make the option Yes so you will be notified in your email that your virtual machine will be shut down at the specified time.
  • Webhook URL: If you want something to happen in sync with the machine being shut down, you can provide the URL.
  • Email address: You can specify the email id where you will get the notification regarding the shutdown of your virtual machine.
auto shutdown azure vm

7. Before 30 minutes, you will get an email saying your virtual machine will shut down.

azure vm auto shutdown

You can Postpone the Azure VM shutdown schedule for 1 hour or 2 hours from the email itself by clicking on the two links below as shown above

  • Postpone: 1 hour
  • Postpone: 2 hours

After you click on Postpone: 1 hour or Postpone: 2 hours link, a new notification will be sent 30 minutes before the new shutdown time.

You can also click on Skip it by clicking on Skip this instance link.

Suppose you want to disable the notification before auto-shutdown From the below window. In that case, you can select No for the “Send notification before auto-shutdown? ” option and then click the Save button.

azure start stop v2

This is how you can enable the Azure virtual machine auto-shutdown option for your Azure virtual machine(VM).

Use Azure CLI to Auto Shutdown Azure VM

We can also use Azure CLI to shut down our Azure Virtual machine. Use the below script to shut down the Azure Virtual Machine.

# You can Stop the Azure VM using below cmdlet
az vm stop --name <Your vm name> --g <Your resource group name>
# You can Deallocate Azure VM using the below cmdlet
az vm deallocate --name <Your vm name> -g <Your resource group name>

Example:

az vm stop --name MyNewVM --g newresgroup

az vm deallocate --name MyNewVM --g newresgroup

Now, you can use the Start-AzVM PowerShell command to start your VM again. If you wish to start or auto-shutdown multiple VMs simultaneously and automate the process, you can check Azure Automation Start/Stop VMs PowerShell.

Enable Auto Shutdown Azure VM PowerShell

Well, if you want to enable the auto-shutdown option in your Azure Virtual Machine using PowerShell, then note that there is no direct PowerShell cmdlet to enable the auto-shutdown

Azure VM Auto-Shutdown ARM Template

It is possible to do it using a simple ARM template, where you can use the cmdlet New-AzureRmResourceGroupDeployment to import the template.

One more way to achieve the same functionality i.e., By using a script with the New-AzureRmResource cmdlet with the properties needed.

You can check out the complete PowerShell script and ARM template here.

Azure virtual machine auto shutdown – Video Tutorial

You may like the following Azure tutorials:

Conclusion

In this Azure tutorial, We discussed the Azure virtual machine auto-shutdown option. Auto shutdown of your virtual machine is a cost-saving way that you can utilize to save a lot of costs while you are not using your VMs. I hope you have enjoyed this article !!!