Skip to content

Instantly share code, notes, and snippets.

@jcefoli
Created August 31, 2017 15:04
Show Gist options
  • Save jcefoli/02caa842d8dcaa5c44ae93fc38cc57fd to your computer and use it in GitHub Desktop.
Save jcefoli/02caa842d8dcaa5c44ae93fc38cc57fd to your computer and use it in GitHub Desktop.
Log off Every Windows User
$computer = $env:computername
$sessions = qwinsta /server:$computer
$sessions = $sessions[1..$($sessions.Count - 1)]
foreach ($Result in $sessions) {
$userName = $Result.Substring(19,22).Trim()
$id = $Result.Substring(41,7).Trim()
if ($userName -ne ""){
rwinsta /server:$computer $id
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment