Exit-PSSession
Published: February 29, 2012
Updated: August 15, 2012
Applies To: Windows PowerShell 2.0, Windows PowerShell 3.0
Exit-PSSession
Aliases
The following abbreviations are aliases for this cmdlet:
- exsn
Syntax
Exit-PSSession [ <CommonParameters>]
Detailed Description
The Exit-PSSession cmdlet ends interactive sessions that you started by using Enter-PSSession.
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, -OutBuffer, and -OutVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/p/?LinkID=113216).
Inputs
The input type is the type of the objects that you can pipe to the cmdlet.
-
None
You cannot pipe objects to Exit-PSSession.
Outputs
The output type is the type of the objects that the cmdlet emits.
-
None
This cmdlet does not return any output.
Notes
-
This cmdlet takes only the common parameters.
Examples
-------------------------- EXAMPLE 1 --------------------------
Description
-----------
These commands start and then stop an interactive session with the Server01 remote computer.
PS C:\>Enter-PSSession -computername Server01Server01\PS> Exit-PSSessionPS C:\>
-------------------------- EXAMPLE 2 --------------------------
Description
-----------
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 (PSSession), 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 the Enter-PSSession cmdlet to start an interactive session using the PSSession in $s.
The third command uses the Exit-PSSession cmdlet 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.
PS C:\>$s = new-pssession -computername Server01PS C:\>Enter-PSSession -session $sServer01\PS> Exit-PSSessionPS C:\>$sId Name ComputerName State ConfigurationName-- ---- ------------ ----- -----------------1 Session1 Server01 Opened Microsoft.PowerShell
-------------------------- EXAMPLE 3 --------------------------
Description
-----------
This command uses the Exit keyword to stop an interactive session started by using the Enter-PSSession cmdlet. The Exit keyword has the same effect as using Exit-PSSession.
PS C:\>Enter-PSSession -computername Server01Server01\PS> exitPS C:\>
Related topics