How to postpone virtual machine from turning on for entire month using autoshutdownschedule

Jasmin Hobden 0 Reputation points
2023-06-08T14:45:49.9666667+00:00

I am trying to postpone the VM from turning on for up to a month by using the autoshutdownschedule tag, I know I can do it by putting in the specific dates, however is there a quicker way?

Thanks very much for any future help,

Jasmin

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
{count} votes

2 answers

Sort by: Most helpful
  1. vipullag-MSFT 26,512 Reputation points Moderator
    2023-06-09T03:47:32.4766667+00:00

    Hello Jasmin Hobden

    Welcome to Microsoft Q&A Platform, thanks for posting your query here.

    Unfortunately, the autoshutdownschedule tag only supports specific dates and times, and there is no built-in way to quickly postpone a VM from turning on for up to a month.

    However, you can achieve this by using Azure Automation and a PowerShell script.

    Here are the high-level steps to achieve this:

    1. Create an Azure Automation account and configure it to manage your VM's.
    2. Create a PowerShell script that will disable the auto-shutdown schedule for your VM.
    3. Schedule the PowerShell script to run at the desired time to disable the auto-shutdown schedule.
    4. Schedule another PowerShell script to run at the desired time to re-enable the auto-shutdown schedule.

    Here is an example PowerShell script that you can use to disable the auto-shutdown schedule for a VM:

    $resourceGroupName = "myResourceGroup"
    $vmName = "myVM"
    
    $vm = Get-AzVM -ResourceGroupName $resourceGroupName -Name $vmName
    $vm.EnableAutoShutdown = $false
    Update-AzVM -ResourceGroupName $resourceGroupName -VM $vm
    

    You can modify this script to include the desired time period for disabling the auto-shutdown schedule. Similarly, you can create another PowerShell script to re-enable the auto-shutdown schedule at the desired time.

    I hope this helps!

    0 comments No comments

  2. msrini-MSFT 9,291 Reputation points Microsoft Employee
    2023-06-09T13:48:04.9466667+00:00

    Hi,

    You can turn off the VM and then set a lock on Azure VM so anyone who wants to turn on will get an error.

    You can read more about Lock here: https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/lock-resources?tabs=json

    Regards,

    Karthik Srinivas

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.