Forum Discussion

Swahlea's avatar
Swahlea
Copper Contributor
Jul 03, 2025

Bulk Start/Stop of Azure Virtual Desktop Session Hosts in a Host Pool via Single Trigger

Hi Community,

We manage an Azure Virtual Desktop (AVD) host pool with a large number of session hosts (e.g., around 100), and we’re looking for a way to start or stop all session hosts in bulk using a single trigger—preferably via PowerShell or an API.

Currently, we use a scheduled script that loops through each VM individually to start or stop them, but this approach doesn't scale well. We’ve noticed that the Azure Portal provides a one-click option to start or stop all session hosts in a host pool, and we’re trying to replicate that behavior programmatically.

What We’re Looking For:

  • PowerShell command or script that can start/stop all session hosts in a host pool without iterating through each VM.
  • If PowerShell doesn’t support this directly, is there an ARM template, Azure CLI command, REST API, or any other method that can be triggered from PowerShell to perform this bulk action?
  • Any official documentation, community guidance, or examples from someone who has achieved this would be greatly appreciated.

Goal:

To simplify and optimize our automation by using a single command or API call to manage all session hosts in a host pool, rather than looping through each machine individually.

Thanks in advance for your help and suggestions!

3 Replies

  • KartikDogra's avatar
    KartikDogra
    Brass Contributor

    why are we not using autoscaling option to shutdown the machines ?

  • I use parallel jobs in PowerShell just like Kidd mentioned.

    Then I use Azure DevOps with a service connection to the subcription hosting the session hosts. The script then executes via a pipeline written i YAML that have the scheduled trigger. 

    If the script fails on some VMs, writing a simple error handling that can be catched and printed by the end of the job can also be useful in Azure DevOps to monitor reboot completion. 

  • How about Azre Automation with parallel jobs:

     

    $sessionHosts = Get-AzWvdSessionHost -ResourceGroupName "YourRG" -HostPoolName "YourHostPool"
    
    $jobs = foreach ($host in $sessionHosts) {
        Start-Job -ScriptBlock {
            param($vmId)
            Start-AzVM -ResourceId $vmId
        } -ArgumentList $host.ResourceId
    }
    
    # Wait for all jobs to complete
    $jobs | Wait-Job

     

Resources