# encoding: ascii
# api: powershell
# title: Log Off Local Users
# description: Logoff all disconnected local users, inspired by this: http://poshcode.org/3285
# version: 0.1
# author: LogOffUsers
# license: CC0
# x-poshcode-id: 6229
# x-archived: 2016-03-29T15:10:14
# x-published: 2016-02-19T21:42:00
#
#
$UserSessions = query.exe session | Select-Object -Skip 1
foreach ($SessionString in $UserSessions) {
    $Session = $SessionString.Split(" ",[System.StringSplitOptions]::RemoveEmptyEntries) 
    if (($Session[2] -eq "Disc") -and ($Session[0] -ne "services")) {
        logoff.exe $Session[1] /V
    }
}
