Share via

Shutdown Idle VM in Azure VDI

Aditya Iyengar 20 Reputation points
2025-09-24T12:44:21.5866667+00:00

I have VDI running for multiple resources in multiple timezones. I need to implement a technique where if the VDI(VM) is idle it has to either hibernate or shutdown as it will save cost.

TIA

Azure Virtual Desktop
Azure Virtual Desktop

A Microsoft desktop and app virtualization service that runs on Azure. Previously known as Windows Virtual Desktop.


Answer accepted by question author

Ankit Yadav 14,455 Reputation points Microsoft External Staff Moderator
2025-09-24T22:54:59.24+00:00

Hello Aditya Iyengar,

You can explore Scaling automation tool mentioned from Microsoft here: https://learn.microsoft.com/en-us/azure/virtual-desktop/scaling-automation-logic-apps#how-the-scaling-tool-works

The scaling tool uses a combination of an Azure Automation account, a PowerShell runbook, a webhook, and a Logic App to function. When the tool runs, the Logic App calls a webhook to start the runbook. The runbook then creates a job.

Peak and off-peak hours are defined as:

  • Peak: The time when maximum user session concurrency is expected to be reached.
  • Off-peak: The time when minimum user session concurrency is expected to be reached.

During peak usage time, the job checks the current number of sessions and the VM capacity of the current running session host for each host pool. It uses this information to calculate if the running session host VMs can support existing sessions based on the SessionThresholdPerCPU parameter defined for the CreateOrUpdateAzLogicApp.ps1 file. If the session host VMs can't support existing sessions, the job starts extra session host VMs in the host pool.

During the off-peak usage time, the job determines how many session host VMs should be shut down based on the MinimumNumberOfRDSH parameter. If you set the LimitSecondsToForceLogOffUser parameter to a non-zero positive value, the job will set the session host VMs to drain mode to prevent new sessions from connecting to the hosts. The job will then notify any currently signed in users to save their work, wait the configured amount of time, and then force the users to sign out. Once all user sessions on the session host VM have been signed out, the job will shut down the VM. After the VM shuts down, the job will reset its session host drain mode.

Please refer this article to know more on how to implement it: https://learn.microsoft.com/en-us/azure/virtual-desktop/set-up-scaling-script

Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful

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.