Share via


PS Script for Logging Off

Question

Tuesday, May 22, 2012 4:02 PM

Due to some mishaps from time to time, is there a simple PowerShell script to log off of one's computer (or, in the sense of remoting in, logging off a remote computer).  For instance, in PowerShell the script for restarting the computer is

restart-computer

Is there a simple command to log off a computer?

All replies (1)

Tuesday, May 22, 2012 6:36 PM âś…Answered

Due to some mishaps from time to time, is there a simple PowerShell script to log off of one's computer (or, in the sense of remoting in, logging off a remote computer).  For instance, in PowerShell the script for restarting the computer is

restart-computer

Is there a simple command to log off a computer?

Try using the logoff executable. Here is the documentation for it:

PS C:\> cmd /c logoff/?Terminates a session.LOGOFF [sessionname | sessionid] [/SERVER:servername] [/V]  sessionname         The name of the session.  sessionid           The ID of the session.  /SERVER:servername  Specifies the Terminal server containing the user                      session to log off (default is current).  /V                  Displays information about the actions performed.PS C:\>

If you type this command from the powershell console, you might have to follow it with an exit command to avoid finding out that the console needs to be closed:

    PS C:\ logoff;exit

Al Dunbar