Skip to content
PowerShell Commands

Exit-PSSession

Exit-PSSession [<CommonParameters>]

The Exit-PSSession cmdlet ends interactive sessions that you started by using the Enter-PSSession cmdlet.

You can also use the Exit keyword to end an interactive session. The effect is the same as using Exit-PSSession .

Parameters

<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,ErrorAction, ErrorVariable, WarningAction, WarningVariable,OutBuffer, PipelineVariable, and OutVariable.

Inputs
None
You cannot pipe objects to this cmdlet.
Outputs
None
This cmdlet does not return any output.
Examples
  1. Start and stop an interactive session:
    PS C:\> Enter-PSSession -computername Server01
    Server01\PS> Exit-PSSession
    PS C:\>
    

    These commands start and then stop an interactive session with the Server01 remote computer.

  2. Start and stop an interactive session by using a PSSession object:
    PS C:\> $s = New-PSSession -ComputerName Server01
    PS C:\>  Enter-PSSession -Session $s
    Server01\PS> Exit-PSSession
    PS C:\> $s
    
       Id Name            ComputerName    State    ConfigurationName
       -- ----            ------------    -----    -----------------
       1  Session1        Server01        Opened   Microsoft.PowerShell

    These commands start and stop an interactive session with the Server01 computer that uses a Windows PowerShell session ( PSSession ).

    Because the interactive session was started by using a Windows PowerShell session, the PSSession is still available when the interactive session ends. If you use the ComputerName parameter, Enter-PSSession creates a temporary session that it closes when the interactive session ends.

    The first command uses the New-PSSession cmdlet to create a PSSession on the Server01 computer. The command saves the PSSession in the $s variable.

    The second command uses Enter-PSSession to start an interactive session using the PSSession in $s.

    The third command uses Exit-PSSession to stop the interactive session.

    The final command displays the PSSession in the $s variable. The State property shows the PSSession is still open and available for use.

  3. Use the Exit keyword to stop a session:
    PS C:\> Enter-PSSession -computername Server01
    Server01\PS> exit
    PS C:\>
    

    This example uses the Exit keyword to stop an interactive session started by using Enter-PSSession . The Exit keyword has the same effect as using Exit-PSSession .

Additional Notes
 * This cmdlet takes only the common parameters.

 *

This work is licensed under a Creative Commons Attribution 4.0 International. It is attributed to Microsoft Corporation and can be found here.

PowerShell Commands