| external help file | System.Management.Automation.dll-Help.xml | |
|---|---|---|
| Locale | en-US | |
| Module Name | Microsoft.PowerShell.Core | |
| ms.date | 12/09/2022 | |
| online version | https://learn.microsoft.com/powershell/module/microsoft.powershell.core/exit-pssession?view=powershell-7.5&WT.mc_id=ps-gethelp | |
| schema | 2.0.0 | |
| aliases |
|
|
| title | Exit-PSSession |
Ends an interactive session with a remote computer.
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.
PS> Enter-PSSession -ComputerName Server01
Server01\PS> Exit-PSSession
PS>These commands start and then stop an interactive session with the Server01 remote computer.
PS> $s = New-PSSession -ComputerName Server01
PS> Enter-PSSession -Session $s
Server01\PS> Exit-PSSession
PS> $s
Id Name ComputerName State ConfigurationName
-- ---- ------------ ----- -----------------
1 Session1 Server01 Opened Microsoft.PowerShellThese commands start and stop an interactive session with the Server01 computer that uses a PowerShell session (PSSession).
Because the interactive session was started by using a 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.
PS> Enter-PSSession -ComputerName Server01
Server01\PS> exit
PS>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.
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
You can't pipe objects to this cmdlet.
This cmdlet returns no output.
PowerShell includes the following aliases for Exit-PSSession:
- All platforms:
exsn
This cmdlet takes only the common parameters.