Guess I should post an answer. Continuing from my comment, seeing as logoff.exe doesn't bind properties like PowerShell cmdlets do when piping to them, youll have to loop through all the results comparing it against the current logged in user, then invoking the utility to log them off via their ID.
Here's my take:
((quser.exe).Trim(' ','>') -replace '\s{20,39}',',,') -replace '\s{2,}',',' | ConvertFrom-Csv |
ForEach-Object -Process {
if ($_.UserName -notmatch "$env:USERNAME")
{
logoff.exe $_.ID
}
}
Another option is to just filter using Where-Object to filter out the logged in user before invoking logoff.exe.
((quser.exe).Trim(' ','>') -replace '\s{20,39}',',,') -replace '\s{2,}',',' | Where-Object -FilterScript { $_ -notmatch "$env:username" } |
ConvertFrom-Csv |
ForEach-Object -Process {
Logoff.exe $_.ID
}
- In terms of filtering, I recommend using the latter example.
This is assuming it's being ran on the local server rather than a remote one.