Powershell - Log off all users?

Kyle picture Kyle · Nov 21, 2012 · Viewed 7.7k times · Source

I was previously using a script found here for logging off all users, however this does not work on certain versions of Windows 7 (specifically windows 7 home. The quser executable does not exist).

Does anyone else have any suggesions on how I can go about logging off all users? The other alternative I was going to attempt was:

(gwmi win32_operatingsystem -computername '.').Win32Shutdown(4)

But this seems to only logoff the current user (I would like to log off all of the users).

Answer

Jeff Zeitlin picture Jeff Zeitlin · Dec 9, 2016

Take a look at the Win32ShutdownTracker method of the WMI Win32_OperatingSystem class. https://msdn.microsoft.com/en-us/library/aa394057(v=vs.85).aspx

I'm using this in a script against remote computers, and it logs off all users and/or reboots the computer.