PowerShell Connect-PSSession Cmdlet
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
In the last blog post, we have discussed Disconnect-PSSession cmdlet in PowerShell.
https://cloudaffaire.com/powershell-disconnect-pssession-cmdlet/
In this blog post, we will discuss Connect-PSSession cmdlet in PowerShell. You can use Connect-PSSession cmdlet to connect to a disconnected PSSession. Using Connect-PSSession cmdlet, you can only connect to the session that were started by you and is in a disconnected state. Connect-PSSession cmdlet cannot be used to connect to PSSession created by others (unless you have the credentials) or if the session state is broken or closed.
Connect-PSSession Cmdlet Syntax:
1 2 3 4 5 6 7 8 9 10 11 |
## Connect-PSSession ## [-Session] ## -Name ## -InstanceId ## [-Id] ## [-IdleTimeoutSec ## [-OutputBufferingMode ## [-ThrottleLimit ## [-WhatIf] ## [-Confirm] ## [ |
Connect-PSSession Cmdlet Argument List:
- –AllowRedirection: Indicates that this cmdlet allows redirection of this connection to an alternate URI.
- –ApplicationName: Specifies the name of an application. This cmdlet connects only to sessions that use the specified application.
- –Authentication: Specifies the mechanism that is used to authenticate user credentials in the command to reconnect to the disconnected session. The acceptable values for this parameter are:
- Default
- Basic
- Credssp
- Digest
- Kerberos
- Negotiate
- NegotiateWithImplicitCredential
- –CertificateThumbprint: Specifies the digital public key certificate (X509) of a user account that has permission to connect to the disconnected session. Enter the certificate thumbprint of the certificate.
- –ComputerName: Specifies the computers on which the disconnected sessions are stored. Sessions are stored on the computer that is at the server-side or receiving end of a connection. The default is the local computer.
- –ConfigurationName: Connects only to sessions that use the specified session configuration.
- –Confirm: Prompts you for confirmation before running the cmdlet.
- –ConnectionUri: Specifies the URIs of the connection endpoints for the disconnected sessions.
- –Credential: Specifies a user account that has permission to connect to the disconnected session. The default is the current user.
- –Id: Specifies the IDs of the disconnected sessions. The Id parameter works only when the disconnected session was previously connected to the current session.
- –InstanceId: Specifies the instance IDs of the disconnected sessions.
- –Name: Specifies the friendly names of the disconnected sessions.
- –Port: Specifies the network port on the remote computer that is used to reconnect to the session.
- –Session: Specifies the disconnected sessions. Enter a variable that contains the PSSession objects or a command that creates or gets the PSSession objects, such as a Get-PSSession command.
- –SessionOption: Specifies advanced options for the session. Enter a SessionOption object, such as one that you create by using the New-PSSessionOption cmdlet, or a hash table in which the keys are session option names and the values are session option values.
- –ThrottleLimit: Specifies 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.
- –UseSSL: Indicates that this cmdlet uses the Secure Sockets Layer (SSL) protocol to connect to the disconnected session. By default, SSL is not used.
- –WhatIf: Shows what would happen if the cmdlet runs. The cmdlet is not run.
PowerShell Connect-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 | Connect-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 Remove-PSSession CmdLet in PowerShell.
To get more details on PowerShell, kindly follow below official documentation