Is there a powershell command I can use to kick "disconnected" users off a server? I can write the script once I know the single line to kick a single user.
For example, I want to kick the 8 users seen in the dialog below.
Disconnects a user from a session that runs on a remote server. The Disconnect-RDUser cmdlet disconnects a specified user from a session that runs on the remote server. All applications continue to run. Use the Invoke-RDUserLogoff cmdlet to end a session and close running applications.
When you want to manually logoff disconnected users from a Remote Desktop server, you can first query the server for those disconnected sessions and then logoff those sessions. Logoff disconnected users on RDS server with powershell: Or if the list is to long you can query the disconnected sessions:
The logoff command is another non-PowerShell command, but is easy enough to call from within a script. In the example above, 'abertram' is logged into the remote computer in session 2. Using the logoff command, we simply need to pass the session ID to the command as an argument and it will dutifully log the user off as expected.
But One thing which i found very interesting is Disconnected User Account on server from long duration and this hampers servers performance. And we should re-mediate this issue as soon as possible, but how? PowerShell has quser and SCOM super able to create an alert using PowerShell , So let’s get started……
I can't try this:
$pc = qwinsta /server:YourServerName | select-string "Disc" | select-string -notmatch "services"
if ($pc)
{
$pc| % {
logoff ($_.tostring() -split ' +')[2] /server:YourServerName
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With