Using PowerShell to control RDS in Windows Server 2012 (Part 2)

If you would like to read the first article in this series please go to Using PowerShell to control RDS in Windows Server 2012.

Introduction

In a previous article, I discussed how to use PowerShell to set up a basic Remote Desktop Services environment. In that article, amongst other things, we discussed how to do a quick RDS deployment, add a Session Collection and add a RemoteApp. In this article we’ll dive a little but deeper into PowerShell for RDS to take a look at how we can even further automate the installation, configuration and maintenance of Remote Desktop Services using the new PowerShell commands available with Windows Server 2012.

Quick Recap

In this article, we will be diving deeper into further deploying a Remote Desktop Services scenario which serves Sessions. We will be focusing on the Session-based desktop deployment. So let’s do a quick recap of what we discussed related to the Session-based desktop deployment in the previous article. The first step was to import the Remote Desktop PowerShell module by using the following command:

import-module RemoteDesktop

We then deployed a Quick Scenario using Session Virtualization by running the following command:
New-SessionDeployment -ConnectionBroker SH01.CRFB.Local -WebAccessServer SH01.CRFB.Local -SessionHost SH01.CRFB.Local
After the deployment, we ran the following command which created a new Session Collection inside the Quick Scenario Deployment.

New-RDSessionCollection -CollectionName MySessionCollection -SessionHost SH01.CRFB.Local -CollectionDescription “This Collection Serves purpose A, B and C” -ConnectionBroker SH01.CRFB.Local

To complete, we finished it off by adding a new RemoteApp to launch WordPad.exe

new-rdremoteapp -Alias Wordpad -DisplayName WordPad -FilePath “C:\Program Files\Windows NT\Accessories\wordpad.exe” -ShowInWebAccess 1 -collectionname MySessionCollection -ConnectionBroker SH01.CRFB.Local

The next steps

From this step forward, we are assuming that the above-mentioned commands have been run. A good way to get an overview of all cmdlets that are available inside the RemoteDesktop PowerShell Module, we run the following command:

get-command -module RemoteDesktop

The output of the command is too large to show it here, but you can easily run the command yourself and check the results. As a next step, we are going to make the WordPad.exe RemoteApp also available on the RD WebAccess page. This can easily be done by making use of the set-rdremoteapp cmdlet. You can use set-rdremoteapp to configure all the settings you would normally do inside the new Server Manager. So to configure our WordPad.exe RemoteApp to become available inside RD WebAccess we use the following command:

Set-RDRemoteApp -CollectionName MySessionCollection -Alias Wordpad -ShowInWebAccess $TRUE -ConnectionBroker SH01.CRFB.Local

When we refresh the RD WebAccess page we are presented with the WordPad RemoteApp, and we have the possibility of launching it from this window.


Figure 1:
WordPad RemoteApp

Now let’s try to do another common configuration with PowerShell. Let’s set up the group that we want to allow access to this WordPad RemoteApp so it will only be accessible for that particular set of users. In order to do so we assume that a group in Active Directory has been created called “GG_WordPad_RemoteApp_Users”. We then run the following PowerShell command:

Set-RDRemoteApp -CollectionName MySessionCollection -Alias Wordpad -UserGroups “GG_WordPad_RemoteApp_Users”-ConnectionBroker SH01.CRFB.Local

If we go to the Server Manager console, we now see that the selected group has exclusive access to this application.


Figure 2:
Server Manager Console

One of the new features with RD WebAccess on Windows Server 2012 (and I’ve seen many requests for this on forums over the past years!) is the ability to create subfolders inside RD WebAccess. With Windows Server 2012, we can now configure this. Obviously, it can also be done via the Server Manager Console, but for the sake of this article let’s use PowerShell.

Set-RDRemoteApp -CollectionName MySessionCollection -Alias Wordpad -FolderName “Basic tools” -ConnectionBroker SH01.CRFB.Local

Running this command will create a subfolder in RD WebAccess called Basic tools, and will move our WordPad RemoteApp to this folder. Then refreshing the RD WebAccess page, we will be able to see the subfolder we requested hosting WordPad.


Figure 3: Creation of subfolder hosting WordPad

Another common setting is configuring the file extensions for a RemoteApp. Since inside the ServerManager GUI file extensions this is configured as a property of the RemoteApp, you would expect that setting the file extension using PowerShell could be done with Set-RDRemoteApp. However, we need to use a different command here called Set-RDFileTypeAssociation.

Set-RDFileTypeAssociation -CollectionName MySessionCollection -AppAlias Wordpad  -FileExtension .docx -IsPublished $true -ConnectionBroker SH01.CRFB.Local

When we now open up the Server Manager Console and look at the properties of the RemoteApp, we can see that the file extension .docx has been added to the RemoteApp.


Figure 4:
RemoteApp Properties

I have tried to add multiple File Extensions at once in various ways, but it seems that the File Extensions parameter of the Set-RDFileTypeAssociation only accepts one File Extension. Errors arise while trying to do so.

 Set-RDFileTypeAssociation -CollectionName MySessionCollection -AppAlias Wordpad  -FileExtension “.odt .rtf” -IsPublished $true -ConnectionBroker SH01.CRFB.Local

Set-RDFileTypeAssociation : The specified file type association cannot be modified because it does not exist.

Before publishing a new RemoteApp, you may want to get an overview of what apps are available on the RD Session Host Servers. A process can be launched that accesses the RD Session Hosts and retrieves a list of programs you may want to add and amongst other properties, outputs the file paths. The command to use here is:
Get-RDAvailableApp -CollectionName MySessionCollection -ConnectionBroker SH01.CRFB.Local

And the output (on an out of the box RD Session host) is as follow:


Figure 5:
List of programs

You can then use this information to publish new RemoteApps using new-rdremoteapp as we did earlier on.

An example of the settings that we are able to do on a Session Collection are those related to the usage of the RD Gateway. Let’s say for example that we want to:

  • specify a specific RD Gateway Server address
  • set the Logon Method to Password Authentication
  • let our users be able to use RD Gateway credentials for Remote Computers (to create Single Sign On)
  • bypass the RD Gateway Server for local addresses.

You’ve guessed it, this can be done in a single PowerShell command which would look like this:
Set-RDDeploymentGatewayConfiguration -GatewayMode Custom -GatewayExternalFqdn rdgw.crfb.nl -LogonMethod Password -UseCachedCredentials $True -BypassLocal $True -ConnectionBroker Sh01.CRFB.Local

Running this command will generate a prompt message:

Confirm
Changing RD Gateway settings of the Remote Desktop deployment. Do you want to continue?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is “Y”):


After we confirm by entering Y and open the Server Manager Console, we can see that the properties related to the use of the RD Gateway have been changed the way we wanted.


Figure 6:
New RD Gateway settings

Another example of a setting that we are able to do with Session Collection is to configure licensing. As you probably know Session-based desktop deployment needs to be licensed with a Client Access License (CAL) which can either be user-based or computer-based. Let’s say that in our example we want to configure the RD Session Host Servers in our deployment to contact a specific license server called LS01.CRFB.Local and we want to use user-based CALs. The PowerShell command for this would be:

set-rdlicenseconfiguration -LicenseServer LS01.CRFB.Local -Mode PerUser -ConnectionBroker SH01.CRFB.Local

Running this command actually results in two prompt messages, one for changing the license setting to user-based CALs and a separate one for changing the license server name.

Confirm
Changing license settings of the Remote Desktop deployment. Do you want to continue?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is “Y”): y
Do you want to continue?
The server(s) ‘LS01.CRFB.Local’ are not valid license server(s).
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is “Y”): y



After we accept both requests, we can go to the Server Manager Console and open the licensing tab of the Deployment Properties, we now see the correct licensing configuration in place.


Figure 7:
Configuring RD licensing

Conclusion

With Windows Server 2012 we can now do any action either from the GUI or using PowerShell Commands. The set of cmdlets inside the RemoteDesktop module is very powerful. Although, we only covered the Session-based desktop deployment in this article, I can assure you that similar commands can be used in Virtual machine-based desktop deployments as well! Remember you can run get-command -module RemoteDesktop to get an overview of all different cmdlets.

If you would like to read the first article in this series please go to Using PowerShell to control RDS in Windows Server 2012.

About The Author

Leave a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top