PowerShell Remove-PSSession Cmdlet
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
In the last blog post, we have discussed Connect-PSSession cmdlet in PowerShell.
https://cloudaffaire.com/powershell-Remove-PSSession-cmdlet/
In this blog post, we will discuss Remove-PSSession cmdlet in PowerShell. You can use Remove-PSSession cmdlet to close a PowerShell session (PSSession) to a local or remote computer. When you invoke Remove-PSSEssion cmdlet, PowerShell stops all the running command in the PSSession, closes the PSSession, and then releases all the resources that were utilized by the PSSession.
Remove-PSSession Cmdlet Syntax:
1 2 3 4 5 6 7 8 9 10 11 12 |
## Remove-PSSession ## [-Id] ## [-Session] ## -ContainerId ## -VMId ## -VMName ## -InstanceId ## -Name ## [-ComputerName] ## [-WhatIf] ## [-Confirm] ## [ |
Remove-PSSession Cmdlet Argument List:
- –ComputerName: Specifies an array of names of computers. This cmdlet closes the PSSessions that are connected to the specified computers. Wildcard characters are permitted.
- –Confirm: Prompts you for confirmation before running the cmdlet.
- –ContainerId: Specifies an array of IDs of containers. This cmdlet removes sessions for each of the specified containers.
- –Id: Specifies an array of IDs of sessions. This cmdlet closes the PSSessions with the specified IDs.
- –InstanceId: Specifies an array of instance IDs. This cmdlet closes the PSSessions that have the specified instance IDs.
- –Name: Specifies an array of friendly names of sessions. This cmdlet closes the PSSessions that have the specified friendly names.
- –Session: Specifies the session objects of the PSSessions to close.
- –VMId: Specifies an array of ID of virtual machines. This cmdlet starts an interactive session with each of the specified virtual machines.
- –VMName: Specifies an array of names of virtual machines. This cmdlet starts an interactive session with each of the specified virtual machines.
- –WhatIf: Shows what would happen if the cmdlet runs. The cmdlet is not run.
PowerShell Remove-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 | Remove-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 Invoke-Command CmdLet in PowerShell.
To get more details on PowerShell, kindly follow below official documentation