Terminal Service Uses

I am looking to remotely invoke a command on ALL production terminal servers in our network to retrieve users logged in. I just need the ‘User’ and the ‘ClientName’ of each session.

I can successfully grab the user name by invoking the ‘Qwinsta’ command on each server, however that just returns the username along with State, type session and ID, but not the ClientName.

I have researched the ‘PSTerminalServices’ module but it doesn’t seem to be available for import.

Does anyone have any suggestions on how to accomplish this?



Its been ages since I had to do anything with terminal services, I thought this would be ‘baked in’.

So I had to go here:
and hit the download button.

I ran the msi (PSTerminalServices.msi) and then imported the module.
Get-TSSession looks like it’ll have what you need.

I ran this:

$users=(get-tssession -cn <servername>)
foreach ($u in $users){
$u |select-object server, UserName, ClientName

It returned a list, however you might want to have it set where the clientname isn’t null, otherwise it returns a bit too much (disconnected sessions and listening service)