Logging Off

Share |

Join PowerShell.com!
Subscribe to Feed

PowerShell eBook
Sign up for
Your PowerTip of the Day:

Award-winning PowerShellPlus


Admin Guide to PowerShell Remoting


Mastering PowerShell eBook

Stop-Computer and Restart-Computer can shutdown and restart a machine, but there are things they cannot do, for example logging off the current user.

Here’s a simple function wrapper that utilizes a standard console application and wraps it into a PowerShell function:

function Invoke-Logoff {
    shutdown.exe /L
}

Twitter This Tip! ReTweet this Tip!


Posted Feb 14 2012, 06:00 AM by ps1

Comments

Marc Johnson wrote re: Logging Off
on 02-14-2012 3:39 PM

Invoke-Logoff (remotely)

function Invoke-Logoff ($compName) { (Get-WMIObject -class Win32_OperatingSystem -Computername $compName).Win32Shutdown(0)}

We can use the Win32Shutdown method with the following Flags to perform additional actions.

0            Log Off

4            Forced Log Off (0+4)

1            Shutdown

5            Forced Shutdown (1+4)

2            Reboot

6            Forced Reboot (2+4)

8            Power Off

12          Forced Power Off (8+4)

msdn.microsoft.com/.../aa394058(v=vs.85).aspx

Copyright 2012 PowerShell.com. All rights reserved.