This tool is using the module PSTerminalService which relies on the Cassia .NET Library.I used Sapien PowerShell Studio 2014 to which make life easier if you want to start building WinForms tools and add PowerShell code.
Once in a while I need to disconnect or close one or more Terminal Sessions on a Windows Server in order to be able to connect via Remote Desktop Protocol or free up a session for someone else.
You would most likely use handy legacy tools such as Qwinsta/Rwinsta, Query/Reset Session or Quser.
|Legacy tools: Qwinsta/Query Session/Quser|
PowerShell WayPSTerminalServices Module
While those legacy tools are great, I was looking for a PowerShell way to deal with what the command line tools had to offer and there was nothing around. Finally I found something very interesting called "PSTerminalServices", a module created by the PowerShell MVP Shay Levy.
This module is based on a .NET library called Cassia which focus on Terminal Session (Remote Desktop) Management Tasks. So basically Shay created some wrappers around it in the form of advanced functions.
Here is a list of the main feature of this module:
Terminal Session Management Tasks:
- Enumerating terminal sessions and reporting session information including connection state, user name, client name, client display details, client-reported IP address, and client build number.
- Logging off a session
- Disconnecting a session.
- Displaying a message box in a session.
- Enumerating all processes or processes for a specified session.
- Killing a process.
- Disconnect-TSSession - Disconnects any attached user from the session.
- Get-TSCurrentSession - Provides information about the session in which the current process is running.
- Get-TSServers - Enumerates all terminal servers in a given domain.
- Get-TSProcess - Gets a list of processes running in a specific session or in all sessions.
- Get-TSSession - Lists the sessions on a given terminal server.
- Send-TSMessage - Displays a message box in the specified session ID.
- Stop-TSProcess - Terminates the process running in a specific session or in all sessions.
- Stop-TSSession - Logs the session off, disconnecting any user that might be connected.
LazyTS is a PowerShell script to manage Terminal Services Sessions and Processes on local or remote machines. It also allows you to Disconnect/Stop sessions and Send Interactive message to one or more sessions.
- 1.0 Initial version
- Session Management: Query/Disconnect
- Processes Management: Query/Stop
- Message : Send message to Session(s)
- PowerShell 3.0
- Cassia Library (included in the download)
LazyTS is relying on the Cassia .NET Library (A DLL file). This file need to be present in the same directory as the script (Either when you use the PS1 or EXE file)
Of course you also need the appropriate permission on the remote machine to be able to manage it.
If the Cassia.dll is not present, the script won't start:
Download and Details
Thanks for reading! If you have any questions, leave a comment or send me an email at email@example.com. I invite you to follow me on Twitter @lazywinadm / Google+ / LinkedIn. You can also follow the LazyWinAdmin Blog on Facebook Page and Google+ Page.