Powershell for remote desktop services

With Microsoft RDS its hard to manage a large infrastucture since you need to manage each server individually. If you have Citrix you have a single console to do everything. But with Windows you have one server that has the Web-interface, you have one server that has the load-balancing role ( broker ) and then you have each TS.

So if you need to do changes to a farm, you would have to logon to the spesific server to remove it from the farm. Of course this would be a pain in the a** if you didn’t have Powershell🙂

Microsoft has done great job to provide Powershell cmdlets for almost every server role in Windows 2008.

You can see the cmdlets avalible here -> http://bit.ly/AlHd8t

But let’s say you want to script a server to join a spesific farm and it will participate in load-balancing, and publish 3 custom applications to display on the  webinterface.

First of you  have to import the module for rds.

Import-Module RemoteDesktopServices

Then you have to change to a virtual directory rds

set-location rds:

If you do a dir there you will see what it contains.

PS RDS:\> dir
Directory: RDS:
Name Type CurrentValue GP PermissibleValues PermissibleOperations
—- —- ———— — —————– ———————
RDSConfiguration Container – Get-Item, Get-ChildItem
RemoteApp Container – Get-Item, Get-ChildItem

The container RDSconfiguration contains the settings in the Remote Desktop Session Host Configurtion and the RemoteApp contains the same for RemoteApp Manager🙂
And since they are containers you can’t do much at this level. So If we change to Remoteapp manager.

Directory: RDS:\RemoteApp dir
Name Type CurrentValue GP PermissibleValues PermissibleOperations
—- —- ———— — —————– ———————
Port Integer 3389 – 1-65535 Get-Item, Set-Item
ServerName String  – Get-Item, Set-Item
ColorDepth Integer 5 – 1, 2, 3, 4, 5 Get-Item, Set-Item
AllowFontSmoothing Integer 1 – 0, 1 Get-Item, Set-Item
CustomRDPSettings String authentication le… – Get-Item, Set-Item
DisableUnlistedPrograms Integer 0 No 0, 1 Get-Item, Set-Item
RDPSetting String redirectclipboard… – Get-Item
DeviceRedirectionSettings Container – Get-Item, Get-ChildItem
RemoteDesktopAccess Container – Get-Item, Get-ChildItem
DigitalSignatureSettings Container – Get-Item, Get-ChildItem
GatewaySettings Container – Get-Item, Get-ChildItem
RemoteAppPrograms Container – Get-Item, Get-ChildItem, New-Item
WebAccessComputers Container – Get-Item, Get-ChildItem, New-Item

If you want to change a setting here. You can use the Set-item name and value.
Like
set-item port 3388 (This will change the port RDP uses)

Publishing an application

So in order to publish a application here. We will have to change to the RemoteAppPrograms directory. And use the command.

PS RDS:\RemoteApp> new-item .\RemoteAppPrograms -name ‘calc’ -applicationpath c:\windows\system32\calc.exe

This  will create a remoteapp and by default it will publish it to Remote Desktop Web Interface.
We can look at the settings by moving to the calc folder and do dir.

PS RDS:\RemoteApp\RemoteAppPrograms\calc> dir
Directory: RDS:\RemoteApp\RemoteAppPrograms\calc
Name Type CurrentValue GP PermissibleValues PermissibleOperations
—- —- ———— — —————– ———————
DisplayName String Windows Calculator – Get-Item, Set-Item
Path String c:\windows\system… – Get-Item, Set-Item
PathExists Integer 1 – 0, 1 Get-Item
IconPath String c:\windows\system… – Get-Item, Set-Item
IconIndex Integer 0 – Get-Item, Set-Item
IconContents String 0,0,1,0,5,0,64,64… – Get-Item
CommandLineSetting Integer 0 – 0, 1, 2 Get-Item, Set-Item
RequiredCommandLine String – Get-Item, Set-Item
ShowInWebAccess Integer 1 – 0, 1 Get-Item, Set-Item
RDPFileContents String redirectclipboard… – Get-Item
UserAssignment Container – Get-Item, Get-ChildItem, New-Item

Something we should have done before publishing the application is to join the server to a farm and participate in load-balancing.

First we can look at the settings for the server.

PS RDS:\RDSConfiguration\ConnectionBrokerSettings> dir
Directory: RDS:\RDSConfiguration\ConnectionBrokerSettings
Name Type CurrentValue GP PermissibleValues PermissibleOperations
—- —- ———— — —————– ———————
ServerPurpose Integer 0 No 0, 1, 2, 3 Get-Item, Set-Item
FarmName String No Get-Item, Set-Item
LoadBalancingState Integer 0 No 0, 1 Get-Item, Set-Item
ServerWeight Integer 100 No 100-10000 Get-Item, Set-Item
ConnectionBroker String No Get-Item, Set-Item
IPAddressRedirection Integer 1 No 0, 1 Get-Item, Set-Item
CurrentRedirectableAddresses Container – Get-Item, Get-ChildItem, New-Item
RedirectableAddresses Container – Get-Item, Get-ChildItem

In order to make a server join the farm, you have to type the command.
Set-item -path RDS:\RDSconfiguration\ConnectionBrokerSettings\Serverpurpose -value 3 -ConnectionBroker test -Farmname TEST -CurrentRedirectableaddresses 192.168.0.24

By using these commands you can script an innstallation of terminal server.

#powershell, #session-host