Remote Desktop Services deployment using Windows PowerShell

by Oct 25, 2012Knowledge Base, Microsoft, News, RDC

Excerpt from MSDN.

Hi, my name is Omair Gillani and I’m a program manager on the Remote Desktop Virtualization team. Remote Desktop Services (RDS) for Windows Server 2012 Release Candidate offers an integrated management experience in the new Server Manager, which makes it easy to deploy, configure, and manage RDS end-to-end. For admins who prefer scripting and automation, one of the great new capabilities added to RDS for Windows Server 2012 Release Candidate is a new Windows PowerShell layer. This provides a powerful mechanism to automate setup for, configure, and manage a complete Remote Desktop Services deployment.

I hope that this post helps you get started deploying Remote Desktop Services by using the Windows PowerShell script.  We focused on providing a great GUI administration experience as well as a great scripting experience.

In this post I focus on using script to deploy a single server virtual machine-based desktop deployment by using a Windows 7 Service Pack 1 (SP1) virtual desktop template image.

Let’s start with the prerequisites.


The requirements for setting up a Remote Desktop Services deployment are as follows:

  1. Install Windows Server 2012 on a Hyper-V capable computer.
  2. Join your server to a domain.
    1. RDS requires all its servers to be added to a domain. The domain needs to have a DHCP server so that IP addresses can be assigned to desktops in a new virtual desktop collection.
  3. Create a virtual desktop template to be used when creating a virtual machine-based desktop deployment.
    1. Specify Win7Gold as the virtual machine name; this virtual desktop template will be used by the Windows PowerShell cmdlets to create virtual desktops for the managed pooled virtual desktop collection.  · The detailed process can be found at Create Virtual Machines.
    2. Install Windows 7 Enterprise with SP1.
    3. Install Hyper-V Integration Services  · From the Hyper-V manager console, select Connect under the Actions pane to launch the virtual machine connection.  · On the Action menu, select Insert Integration Services Setup Diskclip_image002  · In the AutoPlay dialog box, select Install Hyper-V Integration Servicesclip_image004
    4. On the virtual machine, ensure that the operating system has been sysprep generalized by using the following command line:  · sysprep.exe /generalize /shutdown /oobe
  4. Use a domain admin account or a domain user joined to the local Administrators group to run the Windows PowerShell script. The local admin account will not work in this case.
    1. Also ensure that the Windows PowerShell window is launched as administrator.

New Remote Desktop Services deployment

The new Remote Desktop Services virtual machine-based desktop deployment will be set up in two main steps:

  1. Create a new deployment
  2. Create a new Windows 7 SP1 managed pooled virtual desktop collection

You can find the complete script for creating a single server Windows 7 SP1 virtual machine-based desktop deployment on the Script Center The script takes the name of your server as well as the domain it is joined to as parameters.

Create a new deployment

The first step in creating an RDS virtual machine-based desktop deployment is installing and configuring the relevant role services. In Windows Server 2012, a single Windows PowerShell cmdlet will both install and configure the RD Connection Broker, RD Web Access, and RD Virtualization Host role services. The cmdlet also allows for any number of RD Virtualization Host servers to be specified for larger deployments.

Figure 1 below shows the first 14 lines of the Windows PowerShell script that will set up a new RDS deployment on a single server. It takes the name of the Hyper-V capable server as a parameter. The script will install all required RDS role services on this single server. The script imports the RemoteDesktop Windows PowerShell module. It then calls the Windows PowerShell New-RDVirtualDesktopDeployment cmdlet to install the RD Connection Broker, RD Web Access, and RD Virtualization Host role services on the server and configure them to have a working RDS deployment.

  1 param (
  2     [Parameter(Mandatory=$TRUE, HelpMessage="FQDN of RD Web Access\RD Connection Broker and RD Virtualization host roles")]
  3     [String]
  4     $serverName,
  6     [Parameter(Mandatory=$TRUE, HelpMessage="Domain name to be used for new desktops created")]
  7     [String]
  8     $domain
  9 )
 11 # Import the RemoteDesktop module
 12 Import-Module RemoteDesktop
 14 # Create a new RDS deployment
 15 New-RDVirtualDesktopDeployment -ConnectionBroker $serverName `
 16    -WebAccessServer $serverName `
 17    -VirtualizationHost $serverName
 18 Write-Verbose "Created new RDS deployment on: $serverName"

Figure 1: Script lines 1-18

Note: This Windows PowerShell script needs to be run on a remote computer because it requires a restart after installing the RD Virtualization Host role service.

You can use the Get-RDServer cmdlet to get the list of servers and role services that were installed for the newly created RDS deployment.

Create a new managed pooled virtual desktop collection

Now that we have a working RDS deployment, let’s create a new managed pooled virtual desktop collection by using Windows PowerShell. Figure 2 shows the remaining part of the Windows PowerShell script; this will use the New-RDVirtualDesktopCollection cmdlet to create a managed pooled virtual desktop collection by using the virtual desktop template created as part of the prerequisites.

  1 Grant-RDOUAccess -Domain $domain  -OU "Computers" -ConnectionBroker $serverName
  3 # Create a new pooled managed desktop collection
  4 New-RDVirtualDesktopCollection -CollectionName demoPool -PooledManaged `
  5    -VirtualDesktopTemplateName Win7Gold `
  6    -VirtualDesktopTemplateHostServer $serverName `
  7    -VirtualDesktopAllocation @{$serverName = 1} `
  8    -StorageType LocalStorage `
  9    -ConnectionBroker $serverName `
 10    -VirtualDesktopNamePrefix msVDI

Figure 2: Script lines 20-29

This cmdlet will export the template virtual hard disk (VHD) and then create a single virtual machine in the pool and publish this on the RD Web Access portal. We can now connect to the desktop by going through the RD Web Access portal.

This single Windows PowerShell script enabled us to have a completely automated working RDS deployment. The RemoteDesktop module offers the complete range of Windows PowerShell cmdlets that you need to set up, configure, and manage your Remote Desktop Services deployments.

For more information on using Windows PowerShell for Remote Desktop Services also see Travis’s blog at

Related Blogs