Reputation: 87
I need powershell script which show me all users on server in disconnected state. I tried googling but with no luck.
Upvotes: 2
Views: 1624
Reputation: 72151
quser /server:serverName
is the command you are looking for, you could further parse it with PowerShell pretty easily. I don't think there's a more native way.
$username = @()
$sessions = @()
$output = (quser /server:$serverName | select -Skip 1).substring(1)
foreach ($line in $output) {
if ($line -match 'disc') {
$username += ($line -split '\s+')[0]
$sessions += ($line -split '\s+')[2]
}
}
Also, if you want to logout disconnected users:
foreach ($session in $sessions) {
logoff $session /server:$Servername
}
Upvotes: 4