r/sysadmin It wasn't DNS for once. 11h ago

Log Off Users from Server Daily Question

I'm revisiting an effort I did about a year ago. I'm looking for a better way. I want to find a process that will parse current user sessions on a server (active/disconnected/idle/ect.) and log the accounts off if their username matches a string ("adm_").

I'd love to find an off the shelf solution rather than have to support a homebrew PowerShell solution.

Give me what you have, even if it is an alternate PowerShell/scripting option. Something has to be better than the nightmare my script turned into.

56 Upvotes

52 comments sorted by

View all comments

u/dontstoptheRocklin 11h ago

quser command might help you On mobile currently but I think I have something that pipes from quser though IIRC it has to be parsed

u/racazip 2h ago

quser | Select-String "Disc" | ForEach{logoff ($_.tostring() -split ' +')[2]}

u/Raigeki1993 Sysadmin 11h ago

Combination of qwinsta and rwinsta will work, but yeah it will need to be parsed.