it´s been already a few weeks since I´ve released my last article and a lot of great things happened – especially in terms of Autoscaling for our WVD HostPools!
Since last week I´ve been extensively working on a consolidated solution, which is easy to use and supports existing Spring Update Windows Virtual Desktop Host Pools and finally – here it is! This solution combines the best of Microsoft´s scripts, with user interfaces and one single script to rule them all 🙂
The WVDLogix Autoscaling Tool in Preview!
Download it from my GitHub Repo (info, you just need to download the Powershell): https://github.com/wvdlogix/WVDLOGIX-Scripts/blob/master/WVDLogix-AutoScaling/WVDLogix-Autoscaling.ps1
To help you getting started with my script I´ve created a video for you which explains the steps in detail. Please find it here:
Really easy to use right? – Here you can find the detailed documentation
To start with the script the following prerequisites must be fulfilled:
- Have an Azure Subscription and Tenant properly configured
- Have a first Host Pool (the number of machine doesn´t matter)
- Create a Resource Group upfront for your automation resources (to ensure proper separation from other resources)
- Have the Az Powershell Modules installed
Next, you need to download the Powershell script from GitHub using the link above, or by clicking here.
I´ve stored the script in my preferred location, this is C:\WVD\Autoscaling in my example.
Once this is done, all you need to ensure is to start Powershell with elevated rights (Administrator). You can do this by right clicking on the Powershell icon from your startmenu and select “Run as Administrator”.
Now we´re going to navigate to the location were we´ve stored the script in. For me this is C:\wvd\Autoscaling so I switch the directory to it.
Now I can run the script by typing:
The first thing you need to do is to login to your Azure tenant with administrative permissions.
Now, the Autoscaling Tool will ask you to specify a download folder for the working files and scripts by Microsoft, which will be used to finalize the setup process. In my case I select the same folder, where my actual script is and hit enter.
You will see that three more scripts will be downloaded to your computer, let me explain their purpose and in the order they´re executed.
This one will create the Automation Account and Runbook in your environment and import all the required modules you need to run the Autoscaling
To run operations on the virtual machines it´s mandatory to have a “run-as account” in place. As this tool should give you a single place for all operations required, this tool will create this Account for you and provides you with everything you need.
This script is going to create the Logic App in your environment and fills it with the parameters which fit best for your environment. You will see the parameters in detail when we continue.
To make it easy for new users with Powershell / WVD / or Azure in general, I´ve tried to built in as much graphical interfaces as I could (a real GUI will come in the next version).
But for now we can select a Resource Group to place our automation resources in:
This GridView will present you all RGs available in your tenant with your subscription. I select the one I´ve created upfront, which is called KCLD-WE-Automation and click “OK” on the lower right corner to continue.
Now I can select a location for my resources, this will be represented as GridView as well. Please select your option and hit the OK button.
If you want to benefit from gathered logs, you have the possibility to send all those logs to your LogAnalyticsWorkspace. The next question gives you the opportunity to type in the name of your LogAnalyticsWorkspace. This is an optional feature! Just leave it empty and hit enter to continue.
Now the tool is asking you for a secure password, which will be needed to sign the “run-as account”. Please provide a secure password here and hit enter.
And now the tool will create the Automation Account, Runbook and “run-as account” for your environment.
ATTENTION! This process can take between 15-20 minutes! There is no manual action needed in between.
In some cases, especially if you used this script already, it might be possible that you receive an error message at the level of “run-as account” creation. The tool will remediate this issue by itself while informing you that “New-AzRoleAssignment: The role assignment already exists”.
Once this process is done, we need to configure our LogicApp with some parameters, which need to be copied from a few lines above.
Please copy the WebHookURI, represented by the agent and mark it with your mouse and make a right click to copy it. Afterwards paste it in the field below:
Next you need to specify a Tag to exclude resources from being up- and downscaled! This is a great solution in case you want to have a machine 24/7 up and running. You can define this Tag from the Azure Portal or Powershell and just type the value here. In my case I leave it as is and hit enter.
Now, a new window will open, which allows you to select your HostPool. If you have already multiple HostPools, select the one, which shall be automated. Currently there can only be one HostPool automated by the script at a time – you would need to run the script again to also manage another HostPool.
Now you will be prompted for the following parameters in a row. The I will explain each value in brackets!
- Please fill out how often the job shall be repeated, values in minutes, e.g. ’15’ (defines the recurrence interval – can be changed later on)
- Enter the start time for peak hours in local time, e.g. 9:00 (Defines when the automation should start)
- Enter the end time for peak hours in local time, e.g. 18:00 (Defines when the automation should stop)
- Enter the time difference between local time and UTC in hours, e.g. for CET: +2:00 (Defines the timezone, for CET it´s +2:00)
- Enter the maximum number of sessions per CPU that will be used as a threshold to determine when new session host VMs need to be started during peak hours ( Defines the maximum number of sessions per CPU, to determine when new Session Hosts should be started)
- Enter the minimum number of session host VMs to keep running during off-peak hours (Lets you define the resources, that you need to allow computing after the business hours)
- Enter the number of seconds to wait before automatically signing out users. If set to 0, any session host VM that has user sessions, will be left untouched (Allows you to give users time before their sessions will be disconnected in case a downscaling occurs)
- Enter the title of the message sent to the user before they are forced to sign out (The logoff message title)
- Enter the body of the message sent to the user before they are forced to sign out (The logoff body message)
And finally, when everything has configured well, you will see the the logic app scheduler is successfully created.
And finally that´s it! The Autoscaling script has been successfully configured and is able to do it´s job.
In case, that some values aren´t correct or you just want to modify the scheduling / recurrence or any other value, you can run the script again, or navigate to the Azure Portal, into the resource group, where you´ve created all the automation resources and select the Logic App.
On the left-hand side select “Logic app designer”
And now you can see in the center of the screen all values that you are able to change, in case a modifcation is needed.
Click on save in the top left corner and your changes will be immediately active!
I really hope this helps you out there to get started with automation! At this stage, I also want to thank Microsoft for sharing the initial version of the script (Links can be found in the script), which has been modified and consolidated in my tool and which will be used by me to get extended functionalities.
I´m really looking forward to your feedback!