Windows Insider

RDS Rapid Deployment with Hyper-V and VMM

Get servers running Remote Desktop Services (RDS) up and running with just a few clicks.

Servers running Remote Desktop Services (RDS) are in many ways expensive desktops that just so happen to live in the datacenter. RDS is unique in that its servers are likely the only ones where users get direct access to its installed applications.

That makes RDS a special use case for deployment and everyday maintenance. When dozens or even hundreds of users collocate on a single piece of hardware, odds are good that at some point somebody's going to screw something up.

For that reason, troubleshooting some kinds of RDS problems is better accomplished by not troubleshooting at all. A better and faster solution is usually a complete rebuild, a process that's gotten a lot easier thanks to the combination of virtualization and Windows PowerShell.

Not long ago I was asked to design a solution that could rebuild an RDS environment with just a few mouse clicks. With a little effort, some Hyper-V servers, a copy of System Center Virtual Machine Manager (VMM), and some very basic Windows Server VM templates I was able to construct a VMM service template that could be trivially redeployed anytime the environment started to misbehave.

The secret sauce in creating that VMM service template was in defining two separate machine tiers. Into the first tier I installed my Remote Desktop System Host (RDSH) hosts, the application servers my users would interact with. Into the second tier I installed the other RDS role services like the Remote Desktop Connection Broker and Remote Desktop Web Access. Separating out my RDS role services into these two tiers provided a way to scale out the RDSH machine tier to as many servers that my incoming clients needed without being forced into adding new connection brokers and Web servers.

VMM service templates can be equipped with some surprisingly useful logic as they go about their deployment of IT services. One such configuration that's a bit buried in the interface is the ability to set the order for machine-tier deployment.

Somewhat paradoxically, an RDS deployment via a service template works best when its RDSH servers are deployed first. Only after the RDSH servers are available does it make sense to install the RDCB and RDWA role services. The reason for this has to do with the Windows PowerShell commands used to deploy these ancillary role services. One can install and preconfigure RDSH without prerequisites, but cannot do the same with the other components without RDSH present and online.

Windows PowerShell in Windows Server 2012 R2 comes equipped with a small set of RDS cmdlets that facilitate deployment. In most situations outside VMM these cmdlets both install RDS components and connect them together into an RDS deployment and collection. Using VMM, however, the process (at least for me) tends to work better when the VMM handles the role service installation first. The cmdlets then only connect the pieces together to create a fully functioning deployment and collection.

Running these cmdlets in combination with a well-designed VMM service template also adds a further really slick functionality: The ability to scale out and scale in your RDS deployment, specifically the number of RDSH servers you make available for users. My situation required further engineering a no-less trivial solution to add RDSH servers when conditions warrant, and then gracefully remove those servers once the spike in user traffic diminished.

One can build this functionality directly into the VMM service template by first configuring the template to allow scale out. This configuration is done in the properties of each machine tier, and VMM can be configured for a starting number of VMs, as well as a maximum and minimum count of VMs.

All told, the process to complete a system rebuild, scale out the service, or scale it back in required several minutes to complete. But the solution could be accomplished at the click of a button. Completely rebuilding that RDS environment at any point in time immediately became a task I no longer dread.

Construct a Service Template for Deploying RDS
The following instructions assume an environment of Hyper-V machines that are under management by an instance of System Center 2012 R2 Virtual Machine Manager. Appropriate networking and storage have already been configured, hardware and guest OS profiles have been created, and a simple VM template running Windows Server 2012 R2 has been created and stored in the VMM library.

The steps here also create an RDS RemoteApp that's associated with WordPad. This is done merely for testing the success of creating the RDS deployment and collection.

While not discussed in the instructions, additional Windows PowerShell commands could be brought in to facilitate additional software installation or even automated system configuration via Desired State Configuration.

  1. Navigate to the Library node and create a Service Template named RDS Deployment using the blank pattern.
  2. Add a Machine Tier using a customized copy of a VM Template named RDSH Tier. Associate an appropriate Hardware and Guest OS Profile. Change the Computer Name to RDSH##. Add the Remote Desktop Services role along with the Remote Desktop Session Host role service.
  3. Add a second Machine Tier using a customized copy of the VM Template named RDS Web Services Tier and set the Preferred Deployment Order to 2. Associate an appropriate Hardware Profile and the Guest OS Profile. Change the Computer Name to @RDSWebServer@. Add the Remote Desktop Services role along with the Remote Desktop Connection Broker and Remote Desktop Web Access role services.
  4. Navigate to the Application Configuration node in the RDS Web Services Tier properties. Change the Application Profile to Default and set the OS Compatibility to Windows Server 2012 R2 Standard. Add the following three scripts to the application profile:

    First VM When Created 1

    • Script Command Type: Creation: First VM
    • Deployment Order: 1
    • Executable Program: %WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe
    • Parameters: -command New-RDSessionDeployment -ConnectionBroker @[email protected] -WebAccessServer @[email protected] -SessionHost RDSH01.company.pri
    • Run As account: VMM Administrator RunAs
    • Timeout: 3600
    • View Advanced properties and enable output persistence for standard error and standard output with the file paths of c:\stdout-1.txt and c:\stderr-1.txt

    First VM When Created 2

    • Script Command Type: Creation: First VM
    • Deployment Order: 2
    • Executable Program: %WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe
    • Parameters: -command New-RDSessionCollection -CollectionName @CollectionName@ -SessionHost RDSH01.company.pri -ConnectionBroker @[email protected]
    • Run As account: VMM Administrator RunAs
    • Timeout: 3600
    • View Advanced properties and enable output persistence for standard error and standard output with the file paths of c:\stdout-2.txt and c:\stderr-2.txt

    First VM When Created 3

    • Script Command Type: Creation: First VM
    • Deployment Order: 3
    • Executable Program: %WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe
    • Parameters: -command New-RDRemoteApp -Alias Wordpad -DisplayName WordPad -FilePath C:\progra~1\window~3\Access~1\wordpad.exe -ShowInWebAccess 1 -CollectionName @CollectionName@ -ConnectionBroker @[email protected]
    • Run As account: VMM Administrator RunAs
    • Timeout: 3600
    • View Advanced properties and enable output persistence for standard error and standard output with the file paths of c:\stdout-3.txt and c:\stderr-3.txt
  5. Configure the Deployment, entering the value RDSWEB for the RDSWebServer variable and MyCollection for the CollectionName variable. Refresh the preview to obtain placement information and deploy the service.
  6. When the job completes, navigate to \\RDSWEB\c$ and review the standard output and standard error text files that were created by the Windows PowerShell Generic Command Executions.
  7. Next, open Internet Explorer and navigate to http://RDSWEB.company.pri/rdweb. Accept the certificate warning and log in as COMPANY\Administrator. The WordPad application should be available. Click the WordPad icon to launch WordPad, accept any warnings that appear, and verify that it launches correctly.
Enable Scale Out for Deploying RDS
  1. Open the RDS Deployment Service Template in the Designer. View Properties of the RDSH Tier. Enable the tier to be scaled out and increase the maximum instance count. Create an Availability Set for the tier. Navigate to the Application Configuration node. Add the following two scripts to the application profile:

    Other VMs When Created 1

    • Script Command Type: Creation: VMs After First
    • Deployment Order: 1
    • Executable Program: %WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe
    • Parameters: -command Add-RDServer -Server @ComputerName@ -ConnectionBroker @[email protected] -Role RDS-RD-SERVER
    • Run As account: VMM Administrator RunAs
    • Timeout: 3600
    • View Advanced properties and enable output persistence for standard error and standard output with the file paths of c:\stdout-1.txt and c:\stderr-1.txt

    Other VMs When Created 2

    • Script Command Type: Creation: VMs After First
    • Deployment Order: 2
    • Executable Program: %WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe
    • Parameters: -command Add-RDSessionHost -CollectionName @CollectionName@ -SessionHost @ComputerName@ -ConnectionBroker @[email protected]
    • Run As account: VMM Administrator RunAs
    • Timeout: 3600
    • View Advanced properties and enable output persistence for standard error and standard output with the file paths of c:\stdout-2.txt and c:\stderr-2.txt
  2. Locate the RDS Deployment service and choose Scale Out. Select the RDSH Tier and complete the wizard, accepting all the default configurations including the blank virtual machine name.
  3. When the Scale Out job completes, navigate to \\RDSH02\c$ and review the standard output and standard error text files that were created by the PowerShell Generic Command Executions.
Enable Scale In for Deploying RDS
  1. Open the RDS Deployment Service Template in the Designer. Navigate to the Application Configuration node in the RDSH Tier properties. Add the following two scripts to the application profile:

    Other VMs When Deleted 1

    • Script Command Type: Deletion: VMs Before First
    • Deployment Order: 1
    • Executable Program: %WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe
    • Parameters: -command Remove-RDSessionHost -SessionHost @ComputerName@ -ConnectionBroker @[email protected] –Force
    • Run As account: VMM Administrator RunAs
    • Timeout: 3600
    • View Advanced properties and enable output persistence for standard error and standard output with the file paths of c:\stdout-1d.txt and c:\stderr-1d.txt

    Other VMs When Deleted 2

    • Script Command Type: Deletion: VMs Before First
    • Deployment Order: 2
    • Executable Program: %WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe
    • Parameters: -command Remove-RDServer -Server @ComputerName@ -ConnectionBroker @[email protected] -Role RDS-RD-SERVER -Force
    • Run As account: VMM Administrator RunAs
    • Timeout: 3600
    • View Advanced properties and enable output persistence for standard error and standard output with the file paths of c:\stdout-2d.txt and c:\stderr-2d.txt
  2. Locate the RDS Deployment service and choose Scale Out. Select the RDSH Tier and complete the wizard, accepting all the default configurations including the blank virtual machine name. Take note of the steps being created and executed in the Jobs window as the service is deployed.

About the Author

Greg Shields is Author Evangelist with PluralSight, and is a globally-recognized expert on systems management, virtualization, and cloud technologies. A multiple-year recipient of the Microsoft MVP, VMware vExpert, and Citrix CTP awards, Greg is a contributing editor for Redmond Magazine and Virtualization Review Magazine, and is a frequent speaker at IT conferences worldwide. Reach him on Twitter at @concentratedgreg.

Featured

comments powered by Disqus

Subscribe on YouTube