Use PowerShell to Automate Remote Desktop Connection Manager 2.7 Setup

An issue arises

Like many others, I use Microsoft’s Remote Desktop Connection Manager (RDC Man) daily to connect to the Servers I administer. It is a very elegant tool to use.

 

If you don’t already have it, you can download it from Microsoft at: http://www.microsoft.com/en-us/download/details.aspx?id=44989

 

Some of my favorite features include:

  • I can store credentials (with or without passwords) to make quick RDP connections
  • The desktop of each RDP session can be set to automatically resize to fit the RDC Man window.
  • It’s flexible! I can choose to view my RDP sessions inside of RDC Man (docked), or break them out across multiple monitors (un-docked).
  • I can configure servers to inherit settings from the group they are part of in RDC Man.

The list could go on and on. I love this tool! It’s great … except for one thing: it’s a pain to set up the first time, especially when you have a lot of servers to add.

 

I’ll admit the first few times I set up my connections I did it by hand. Then I realized that the connection file is just a plain text file, so I started copying and pasting. However, recently I have found myself again in a position where I need to add many connections from a new environment. I’ll admit I wasn’t looking forward to setting RDC Man up.

PowerShell to the rescue

A philosopher somewhere once said, “It is when we dread doing something that we become most inventive.” He must have been a really smart guy, because I decided then and there that I wasn’t going to hand code my RDC Man connection files anymore! I was going to automate it!

 

The resulting PowerShell script reads the site information on a Primary SCCM 2012 Site and automatically builds a RDC Man connection file, including smart groups that allow you to quickly view a list of servers by the role it is assigned.

 

Here are some screenshots of what it will look like when finished:

The list of Connection Groups. One normal group that includes all servers, and one smart group for every role present in SCCM.

The list of Connection Groups. Using PowerShell, we will create one normal group that includes all servers, and one smart group for every role present in SCCM.

 

Properties of a single server. The display name includes the site code and server name. The comment includes all the SCCM roles the server has installed.

Properties of a single server. We will use PowerShell to add the display name, using the site code and server name. The comment includes all the SCCM roles the server has installed.

 

Properties of one of the “Smart Groups”. The groupings key off the comments included for each server.

Properties of one of the “Smart Groups”. The groupings key off the comments we included using PowerShell for each server.

 

How to automate it with PowerShell

 

The script itself is rather simple, actually. I’ll walk you through how it works, then at the bottom of this post, I’ll include the entire script in case you want to try it out!

 

Note: This script must be run on the Primary Site server.

 

We start by initializing a few variables:

 

$OutputText will be used to hold the contents of the RDC Connection file that we will export at the end of the script.

 

 

 

$ServerList will be used to build a list of all site servers listed in SCCM.

 

 

 

$ServerInfo is an array and will be used to build a custom PSObject to help build the output file.

 

 

 

 

We query WMI on the SCCM Site server and get back a list of all site servers with their site code and role, which we store in $SiteServers. Replace the “xxx” with your site code.

 

 

 

Due to the fact that many servers have more than one role, we put a list of unique server names into $UniqueServers.

 

 

 

Next we use a Foreach loop to pull the actual server name out of the SiteSystem field. This leaves us with a clean comma seperated list of unique server names (minus the extra text).

 

We use the powershell “Split” function to turn the $ServerList variable into an array of server names.

 

This next few steps are done once for each server. We build a list of the roles that a server is assigned. Due to the fact that servers commonly contain more than one role, we are going to put this into a comma separated list also. We trim off the last comma at the end so our list is clean.

 

 

 

We get the site code of the server that we are working on ($Server).

 

 

We create a custom object for the server we are looking at, and add the Name, Roles, and Sitecode properties. Then we reinitialize the variables to prepare to process the next server.

 

 

Once we are done with the loop above, the $ServerInfo variable contains an array of custom objects, one for each server.

 

Now we start to build the output file. We create the “Header” of the RDC file using a literal string to preserve the line breaks for readability.

 

 

We then loop through our custom server object to build the “static” connection node for each server.   These will be contained in the “All Servers” group.

 

 

Next we build out our smart groups for each role that is present in our SCCM hierarchy. We pull this from WMI again so we have a unique list. Once again, replace the xxx with your site code.

 

 

 

We loop through each role and create smart group for it, based on the comments we added to the server connections above.

 

 

We write the footer of the RDC file to close it out gracefully.

 

 

Finally, we place the RDG file on the desktop of the current user and display a message that we are done.

 

 

 

Putting it all together

Now, as promised, here is the entire script.

By |2019-01-25T08:33:32+00:00October 28th, 2015|PowerShell, SCCM|0 Comments

About the Author:

steve bowman

Model Technology

Let us help you get your end point and data center strategy on cruise control!  Ask about our Calibration Assessment.

CONTACT US

  • 12125 Woodcrest Executive Drive, Ste. 204 Creve Coeur, MO 63141
  • (314) 254-4138
  • sales@model-technology.com

RECENT TWEETS