2014/10/04

PowerShell GUI - LazyTS (Terminal Services Management)


LazyTS is a PowerShell script to manage Sessions and Processes on local or remote machines. It allows you to Query/Disconnect/Stop session(s), Query/Stop process(es) and Send Interactive message to one or more sessions.

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.


Legacy Tools

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/RwinstaQuery/Reset Session or Quser.

Legacy tools: Qwinsta/Query Session/Quser

PowerShell Way

PSTerminalServices 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:
  1. 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.
  2. Logging off a session
  3. Disconnecting a session.
  4. Displaying a message box in a session.
  5. Enumerating all processes or processes for a specified session.
  6. Killing a process.
PSTerminalServices cmdlets:
  • 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

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.


Version

  • 1.0 Initial version
    • Features
      • Session Management: Query/Disconnect
        • Stop
      • Processes Management: Query/Stop
      • Message : Send message to Session(s)

Requirements

  • 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 fxcat@lazywinadmin.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.

1 comment: