Some background. We currently use RD for our users to access our main EMR. This way we offload the workload to Servers, not local machines.

Anyway… one of the issues I run into is that sometimes, the session will hang. We cannot isolate the issue, but it happens periodically. While we work that out, right now our process is:

log into the ConnectionBroker > Wait for the Host to populate > find the user > logoff the session remotely.

I was playing with Powershell yesterday, I am a COMPLETE N00B when it comes to this, I recently returned to IT from a decade long trip as an installer. I was able to cobble together some Powershell commands to keep me from having to remote into the server.

Currently I use: Get-RDUserSession -ConnectionBroker “Broker.office.local”

This pulls a list of connected users.

Then I identify the RD Server they are on, (out of 3) and the Unified Session ID and log it off using

Invoke-RDUserLogoff -HostServer “appserver(number).office.local” -UnifiedSessionID (number) -Force

While this is WAY faster than going into the server… I want to be able to parse the UserName, have it show me only the offending sessionID, so I can kill it automatically using the Username…

Any Thoughts on how to create this script? my Google-Fu is weak today.

3 Spice ups

Check out the script this guy put together. Should suite your needs or at least give you a head start on a custom PS script.

https://community.spiceworks.com/scripts/show/2858-powershell-find-and-log-off-remote-desktop-users-server-2012

2 Spice ups

looks amazing… I am trying to connect it to my uses now… but, it makes some assumptions that I am not sure about… thanks for the link!