Update with Breadth-First! Auto Scale Session Hosts in Windows Virtual Desktop Spring Update (ARM) with Azure Function

I am excited to announce a significant update to the Auto Start and Stop script for WVD.  This update adds a new option that works with the peak time settings to change the load balancing type from Depth-First to Breadth-First.  When used, it also starts all available session hosts during peak time to accommodate the user load. 

At the end of peak time, the host pool goes back to Depth-First load balancing, and session hosts shut down as users log off.  Providing a cost savings auto scale solution during times of low demand.

The new feature is optional.  If not enabled, the script will work just as it did before, starting and stopping session hosts based on the user load and the server start threshold.  The new Use Breadth-First During Peak option provides capacity for the greatest number of users while leveraging Dept-First during the off-peak time to consolidate user connections and shut down unused Session Hosts.

For full details on the script’s functionality and deployment overview, see the previous video on the Auto Start and Stop script located here: https://www.ciraltos.com/auto-start-and-stop-session-hosts-in-windows-virtual-desktop-spring-update-arm-edition-with-an-azure-function/

The Script can be found at my GitHub page here:  https://github.com/tsrob50/WVD-Public/blob/master/WVDARM_ScaleHostPoolVMs.ps1

The $usePeak variable must be set to true to enable the new functionality.  The new $useBreadthFirstDuringPeak must also be set to true to enable  Breadth-First load balancing during peak time. 

Use Breadth-First option

To use peak time without changing to Breadth-First load balancing, simply set $usePeak to True and $useBreadthFirstDuringPeak set to $false

Do not use Breadth-First option

7 thoughts on “Update with Breadth-First! Auto Scale Session Hosts in Windows Virtual Desktop Spring Update (ARM) with Azure Function

  1. getting an error when this is deployed…

    2021-01-18T22:35:02.295 [Error] ERROR: No hosts available to shut downException :Type : Microsoft.PowerShell.Commands.WriteErrorExceptionMessage : No hosts available to shut downHResult : -2146233087CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorExceptionFullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Stop-SessionHostInvocationInfo :MyCommand : Stop-SessionHostScriptLineNumber : 242OffsetInLine : 9HistoryId : 1ScriptName : D:\home\site\wwwroot\TimerTrigger1\run.ps1Line : Stop-SessionHost -SessionHosts $sessionHosts -hostsToStop $hostsToStopPositionMessage : At D:\home\site\wwwroot\TimerTrigger1\run.ps1:242 char:9+ Stop-SessionHost -SessionHosts $sessionHosts -hostsToStop $ho …+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~PSScriptRoot : D:\home\site\wwwroot\TimerTrigger1PSCommandPath : D:\home\site\wwwroot\TimerTrigger1\run.ps1InvocationName : Stop-SessionHostCommandOrigin : InternalScriptStackTrace : at Stop-SessionHost, D:\home\site\wwwroot\TimerTrigger1\run.ps1: line 91at , D:\home\site\wwwroot\TimerTrigger1\run.ps1: line 242Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException : Result: ERROR: No hosts available to shut downException :Type : Microsoft.PowerShell.Commands.WriteErrorExceptionMessage : No hosts available to shut downHResult : -2146233087CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorExceptionFullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Stop-SessionHostInvocationInfo :MyCommand : Stop-SessionHostScriptLineNumber : 242OffsetInLine : 9HistoryId : 1ScriptName : D:\home\site\wwwroot\TimerTrigger1\run.ps1Line : Stop-SessionHost -SessionHosts $sessionHosts -hostsToStop $hostsToStopPositionMessage : At D:\home\site\wwwroot\TimerTrigger1\run.ps1:242 char:9+ Stop-SessionHost -SessionHosts $sessionHosts -hostsToStop $ho …+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~PSScriptRoot : D:\home\site\wwwroot\TimerTrigger1PSCommandPath : D:\home\site\wwwroot\TimerTrigger1\run.ps1InvocationName : Stop-SessionHostCommandOrigin : InternalScriptStackTrace : at Stop-SessionHost, D:\home\site\wwwroot\TimerTrigger1\run.ps1: line 91at , D:\home\site\wwwroot\TimerTrigger1\run.ps1: line 242Exception: No hosts available to shut downStack:

    this is in a host pool with 2 running VM – both currently with 0 users… so obviously one should be shut down with the script.

  2. I have to say this script is excellent piece of work. Setup for really easy and quick. Few settings to configure and it’s good to go.

  3. We have a pool of 2 WVD machines. Is there any way to specify a particular machine to be on 24×7 and have the other machine scale as required?

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.