Created
August 31, 2017 15:04
-
-
Save jcefoli/02caa842d8dcaa5c44ae93fc38cc57fd to your computer and use it in GitHub Desktop.
Log off Every Windows User
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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