mastergat
mastergat

Reputation: 15

Powershell Win32_ServerConnection on TS Server 2012 no result

I'm trying to execute a simple command on one of a TS part of a RDS farm and I get no result. I just want to see every connection on the TS using:

 Get-WmiObject Win32_ServerConnection -ComputerName MYTSSERVER

and I get no result at all. Any idea what could be the cause?

Thank you

Upvotes: 0

Views: 340

Answers (1)

omniomi
omniomi

Reputation: 130

Win32_ServerConnection shows active connections to network shares on the machine. If you do not have active network shares or connections to them there will be no results.

I assume since they're terminal servers in an RDS farm that you're looking for remote sessions in which case you want Win32_LoggedOnUser. That said, Win32_LoggedOnUser doesn't clear sessions that have been disconnected or even closed. It shows all sessions since the last computer reboot whether that information is still valid or not.

It's incredibly annoying but the best way to list real and active sessions is to list all copies of explorer.exe running on the machine and who they belong to or use the cmd application query.exe. There are ways in PowerShell to turn the output of query.exe into objects:

$Users = query user /server:TERMSERV01 2>&1
$Users = $Users | ForEach-Object { (($_.trim() -replace ">" -replace "(?m)^([A-Za-z0-9]{3,})\s+(\d{1,2}\s+\w+)", '$1  none  $2' -replace "\s{2,}", "," -replace "none", $null)) } | ConvertFrom-Csv
$Users

Upvotes: 1

Related Questions