top of page

PowerShell - Logoff all Disconnected/Stale logon sessions Remote Server

  • Writer: Jon Boyette
    Jon Boyette
  • Jan 10, 2022
  • 1 min read

Fantastic script that prompts for the server name, then ALL sessions that are logged off or disconnected on the remote server are cleared, Active connections are not affected.


$ServerList = Read-Host "Enter ServerName to Logoff ALL Disconnected sessions"

foreach ($server in $ServerList)

{

quser /server:$server | ? { $_ -match “Disc” }|foreach {

$Session = ($_ -split ‘ +’)[2]

$user = ($_ -split ‘ +’)[1]

$idletime= ($_ -split ‘ +’)[4]

Write-host “You are about to log off user $user with session id $Session who is idle for $idletime ”

logoff $Session /server:$server

}

}



 
 
 

Recent Posts

See All
PowerShell - List All Domain SPNs

Save as same List_ALL_SPNs.ps1 or similar, this LDap calls the Domain for all Service Principal names and accounts related #Build LDAP...

 
 
 
PowerShell - Start-Monitoring

This is a great script used to Monitor and Email if a server is up or down, once ran, and smtp and from address is set, then run:...

 
 
 

Comments


Post: Blog2 Post
  • Facebook
  • Twitter
  • LinkedIn

©2022 by Boyette Technical Services. Proudly created with Wix.com

bottom of page