PowerShell Disconnect-PSSession Cmdlet
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
In the last blog post, we have discussed Exit-PSSession cmdlet in PowerShell.
https://cloudaffaire.com/powershell-exit-pssession-cmdlet/
In this blog post, we will discuss Disconnect-PSSession cmdlet in PowerShell. You can use Disconnect-PSSession cmdlet to disconnect a PSSession from a local or remote computer. Using Disconnect-PSSession cmdlet, you can only disconnect open PSSessions that are connected to the current session. Disconnect-PSSession cmdlet cannot be used to disconnect a broken or closed PSSession. When you disconnect an open PSSession, the commands that are still executing on that session will continue to execute till the session timeout period reached, only new command will not run on the disconnected session. You can connect to a disconnected session using Connect-PSSession cmdlet.
Disconnect-PSSession Cmdlet Syntax:
1 2 3 4 5 6 7 8 9 10 11 |
## Disconnect-PSSession ## [-Session] ## -Name ## -InstanceId ## [-Id] ## [-IdleTimeoutSec ## [-OutputBufferingMode ## [-ThrottleLimit ## [-WhatIf] ## [-Confirm] ## [ |
Disconnect-PSSession Cmdlet Argument List:
- –Confirm: Prompts you for confirmation before running the cmdlet.
- –Id: Disconnects from sessions with the specified session ID. Type one or more IDs (separated by commas), or use the range operator (..) to specify a range of IDs.
- –IdleTimeoutSec: Changes the idle timeout value of the disconnected PSSession. Enter a value in seconds. The minimum value is 60 (1 minute).
- –InstanceId: Disconnects from sessions with the specified instance IDs.
- –Name: Disconnects from sessions with the specified friendly names. Wildcards are permitted.
- –OutputBufferingMode: Determines how the command output is managed in the disconnected session when the output buffer is full. The default value is Block. Valid values are:
- Block: When the output buffer is full, execution is suspended until the buffer is clear.
- Drop: When the output buffer is full, execution continues. As a new output is saved, the oldest output is discarded.
- None: No output buffering mode is specified.
- –Session: Disconnects from the specified PSSessions. Enter PSSession objects, such as those that the New-PSSession cmdlet returns. You can also pipe a PSSession object to Disconnect-PSSession.
- –ThrottleLimit: Sets the throttle limit for the Disconnect-PSSession command. The throttle limit is the maximum number of concurrent connections that can be established to run this command. If you omit this parameter or enter a value of 0, the default value, 32, is used.
- –WhatIf: Shows what would happen if the cmdlet runs. The cmdlet is not run.
PowerShell Disconnect-PSSession Cmdlet:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
################################################ ## PowerShell | Cmdlet | Disconnect-PSSession ## ################################################ ## PowerShell Latest Version (5) ## Run PowerShell as admin ## create a new PSSession with a remote computer New-PSSession -ComputerName "System1" -Name "MyPsSession" ## get PSSession details Get-PSSession ## enter interactive PSSession with a remote computer Enter-PSSession -Name "MyPsSession" ## execute any command on a remote computer hostname ## exit interactive PSSession with a remote computer Exit-PSSession ## disconnect PSSession with a remote computer Disconnect-PSSession -Name "MyPsSession" Get-PSSession ## connect to a disconnected pssession with a remote computer Connect-PSSession -Name "MyPsSession" ## remove PSSession with a remote computer Remove-PSSession -Name "MyPsSession" |
Hope you have enjoyed this article. In the next blog post, we will discuss Connect-PSSession CmdLet in PowerShell.
To get more details on PowerShell, kindly follow below official documentation