Once we have our RDS deployment, we would like to setup Remote Desktop Session Host autoscaling depending on connections in our Connection Broker, so we can deliver more power during logon storms and then scale down after those peaks. This tutorial follows Microsoft steps, allowing you to setup automatic Remote Desktop Session Host scale up/down by using Azure Automation. While this is showing how to automate depending on the user workload, you can setup an schedule on the workbook to scale up Remote Desktop Session Host before the storm occurs.
The environment to be used to execute the script must meet the following requirements.
- An RDS deployment in Azure under Azure Resource Manager mode with 2 or more RDSH servers in a collection, and each Azure virtual machine name has the same name as the hostname of the operating system running on that virtual machine.
- Internet access from the Remote Desktop Connection Broker (RD Connection Broker) server.
- PowerShell 4.0 or higher (default for Windows Server 2012 R2) installed on the RD Connection Broker server. (The script must be run on the VM with the RD Connection Broker role service installed). Since we have deployed VMs with Windows Server 2016 by using the resource manager templates, this is covered
- Microsoft Azure Resource Manager PowerShell Module installed on the RD Connection Broker server. You can download and install the Azure Resource Manager PowerShell modules by running
Install-Module AzureRM
in PowerShell as shown below.
Windows PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.
PS C:\WINDOWS\system32> Install-Module AzureRM
Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its
InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from
'PSGallery'?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): Y
- Create an Azure Active Directory application and service principal that can access resources.
- Click Azure Active Directory > App registrations > New application registration
- Provide a name and URL for the application. Select either Web app / API or Native for the type of application you want to create. After setting the values, select Create.
- Get application ID and authentication key
- Click Subscriptions > your-Azure-Subscription > Access Control (IAM) > Add and fill the form
- Click Azure Active Directory > App registrations > New application registration
Use the following procedure to deploy the script.
- Logon to the RD Connection Broker server using a domain administrative account.
- Create a folder on the RD Connection Broker server (e.g. c:\DynamicRDSH)
- Download the RDSScaler.ps1 and Config.xml files from this lab > Virtual Labs > Deploy > Architecture-HA > Scripts and copy them to the folder.
- Update the Config.xml file with the Azure subscription information, resource group, and the RD Connection Broker. Open the Config.xml file using Notepad.
- Replace the AADTenantId value with your Azure Tenant Id. You can find it by clicking Azure Active Directory > Properties:
TenantID - Replace the AADApplicationId Value with the application id you created.
- We will be using password authentication to run the script, replace the AADServicePrincipalSecret value with the application key value copied before.
- Replace the CurrentAzureSubscriptionName value with your Azure subscription name. You can find it here:
- Replace the ResourceGroupName value with the resource group name your RDS environment deployed.
- Save the Config.xml file.
- Replace the AADTenantId value with your Azure Tenant Id. You can find it by clicking Azure Active Directory > Properties:
- Configure the Task Scheduler to run the RDSScaler.ps1 file at a regular interval
- In RD Server Manager (RDBE-VM01), select Tools, and Task Scheduler.
- In the Task Scheduler window, select Create Task …
- In the Create Task dialog, select the General tab, enter a Name: (e.g. Dynamic RDSH), select Run whether user is logged on or not and Run with highest privileges, and select Windows server 2016 in "Configure for" section
- Select the Triggers tab and New…
- In the New Trigger dialog, under Advanced settings, check Repeat task every and select the appropriate period and duration (e.g. 15 minutes and Indefinitely).
- Select the Actions tab and New…
- In the New Action dialog, type powershell.exe in the Program/script: field and type C:\DynamicRDSH\RDSScaler.ps1 in the Add arguments (optional): field.
- Select OK to accept defaults under the Conditions and Settings tabs
- Enter the password for the administrative account used to run the script.