ConnectedUsers is a PowerShell module that provides cmdlets to query and disconnect local and remote user sessions.
Get-ConnectedUser(aliases:Get-QUser,gcu): Retrieves information about user sessions.Remove-ConnectedUser(aliases:Remove-QUser,rcu): Disconnects a specified user session.
You can install the ConnectedUsers module from the PowerShell Gallery: Link to the Gallery Page
After installation, import the module:
Import-Module ConnectedUsersTo retrieve all user sessions on the local machine:
Get-ConnectedUserTo retrieve sessions on remote machines:
Get-ConnectedUser -ComputerName "RemotePC1", "RemotePC2"To logoff a user session by specifying the Session ID:
Remove-ConnectedUser 1To disconnect a user session on a remote machine:
Remove-ConnectedUser -SessionId 2 -ComputerName "RemotePC"To logoff a specific user from multiple machines:
$userName = "thisguy"
Get-ConnectedUser -ComputerName "RemotePC1", "RemoteServer1" | Where-Object { $_.UserName -eq $thisGuy } | Remove-ConnectedUser