locked
PS Script for Logging Off RRS feed

  • Question

  • 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?
    Tuesday, May 22, 2012 4:02 PM

Answers

  • 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

    • Proposed as answer by Just Karl Tuesday, May 22, 2012 9:27 PM
    • Marked as answer by Yan Li_ Monday, May 28, 2012 2:12 AM
    Tuesday, May 22, 2012 6:36 PM