Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell command to kick disconnected users off a server

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.

enter image description here

like image 336
user952342 Avatar asked Jan 17 '13 18:01

user952342


People also ask

How do I Disconnect a user from a remote server?

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.

How to manually logoff disconnected users from a remote desktop server?

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:

How do I log off a user from another computer?

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.

Does disconnected user account hampers server performance?

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……


1 Answers

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 

  }
}
like image 143
CB. Avatar answered Sep 24 '22 23:09

CB.