Extending Remote Desktop Services via PowerShell – Part 4

(Post courtesy Manoj Ravikumar Nair, who you can follow on his excellent blog at http://www.powershell.ms)

Previous Post: Extending Remote Desktop Services via PowerShell – Part 3

Configuring a RDS Farm using PowerShell

So far, we have installed two RD Session Host Servers, added some RemoteApps, configured the Session Host Servers, installed the Web Access Server, installed and configured the Connection Broker.

We are all set to create a RDS Farm. I have already created the related DNS records (RDSFARM) as shown in the screenshot below:


Let’s connect to our RD Session Host Server COLFAX and navigate to the ConnectionBrokerSettings Container


Before we start creating a FARM, we need to figure out the corresponding value of the FARM membership as defined in the ServerPurpose Property.

As you can see in the screenshot below, the value 3 corresponds to the Farm Membership.

dir .\ServerPurpose | fl *


We also need to the IP address of the NIC attached to the Session Host Server (RedirectableAddresses)


To create a FARM, we can run the following command

Set-Item ServerPurpose -value 3 -ConnectionBroker <FQDN-OF-RD-CONNECTIONBROKER- GOES-HERE> -FarmName <FQDN-FARM-NAME-GOES-HERE> -IPAddressRedirection 1 -CurrentRedirectableAddresses <IP-ADDRESS-YOU-WANT-TO-USE-GOES-HERE>

Since, we have only one NIC card attached to each of the RD Session Host Servers, the value of the CurrentRedirectableAddresses can be substituted by the Name Property of the RedirectableAddresses as shown in the figure below


In the above case, we are storing all the contents of the RedirectableAddresses container into a PowerShell variable called $currentaddress.

Now, let’s take a look at the members of the $currentaddress


Notice that $currentaddress is a Custom TSObject and has the Name as a Property. To just display the contents of the Name Property, run $currentaddress.Name as shown below


Now, let’s re-examine the original syntax for creating the FARM

Set-Item ServerPurpose -value 3 -ConnectionBroker <FQDN-OF-RD-CONNECTIONBROKER- GOES-HERE> -FarmName <FQDN-FARM-NAME-GOES-HERE> -IPAddressRedirection 1 -CurrentRedirectableAddresses <IP-ADDRESS-YOU-WANT-TO-USE-GOES-HERE>

Based on our current environment, the values for the Parameters above would be as follows:

-ConnectionBroker - Liberty.powershell.ms

-FarmName – RDSFARM.powershell.ms

-IPAddressRedirection – 1 {this implies that IP address redirection is enabled}

-CurrentRedirectableAddresses - $currentaddress.Name {this implies that the value of the CurrentRedirectableAddresses can be obtained from the Name Property of the RedirectableAddresses Container}

So here is the logic that we would apply

1) Connect to the RDS PowerShell Drive

2) Store the value of the Name Property of the RedirectableAddresses in a PowerShell variable called $currentaddress

3) Run the base script for creating a farm by substituting the values

Step 1:-


Step 2:-


Step 3:-


That’s all about it. Let’s check the properties of the RD Session Host Server.



Now, you must be wondering why did I take the pain of storing the value of the IP Address into a variable and not just directly assign it to the CurrentRedirectableAddresses. Assigning the values directly will work for one or two servers, but when you want to add say about 10 servers into the FARM, you will have to go to each server and run this script.

Wouldn’t it be easier, if we could get a list of computers, pass it as an input to a script that will connect to each computer in the list and configure the FARM settings.

It is a pretty simple script as given below. Here, I assume that you have saved the computer names, one per line, into a Text file called Servers.txt in the C:\Scripts Directory

Get-Content C:\Scripts\Servers.txt | Foreach-Object {

$session = New-PSSession –ComputerName $_

Invoke-command –Session $session –ScriptBlock { ipmo RemoteDesktopServices;$currentaddress = dir –Path RDS:\RDSConfiguration\ConnectionBrokerSettings\RedirectableAddresses; Set-Item –Path RDS:\RDSConfiguration\ConnectionBrokerSettings\ServerPurpose –Value 3 –ConnectionBroker ‘Liberty.powershell.ms’ –FarmName ‘RDSFARM.powershell.ms’ –IPAddressRedirection 1 –CurrentRedirectableAddress $currentaddress.name}

Get-PSSession | Remove-PSSession


Now that we have our script ready, I just removed the Colfax server from the FARM Membership as shown below:


In this way, I can test whether the script is working as expected. I also created a text file called Servers.txt which contains the names of our two RD Session Host Servers. PowerShell Remoting has been enabled on both the Session Host Servers.


Now, it’s the time to run the script. I have changed the default script execution behavior of PowerShell to Unrestricted


Okay, we have a good start. The Script ran without errors and returned the cursor back on the next prompt. But did it do what it was supposed to do?

Let’s take a quick look at the RD Connection Broker Properties of both, COLFAX and FUJI.





Yipeeeeeeee!!, it worked as expected. J This is the ‘Power of PowerShell’. By just using a simple logic, and a few lines of code, we were able to automate the creation of a RDS FARM.

Next Post: Extending Remote Desktop Services using PowerShell – Part 5

Skip to main content