Enter-PSSession

Start an interactive session with a remote computer. This allows running multiple commands.

Syntax
      Enter-PSSession [-ComputerName] string [-ApplicationName string]
         [-Authentication {Default | Basic | Negotiate | NegotiateWithImplicitCredential | Credssp | Digest | Kerberos}]
            [-Port Int32]  [-UseSSL][-CertificateThumbprint string]  [-ConfigurationName string]
               [-Credential PSCredential] [-SessionOption PSSessionOption] [-EnableNetworkAccess] [CommonParameters]

      Enter-PSSession [[-ConnectionUri] Uri] [-AllowRedirection]
         [-Authentication {Default | Basic | Negotiate | NegotiateWithImplicitCredential | Credssp | Digest | Kerberos}]
            [-CertificateThumbprint string] [-ConfigurationName string] [-EnableNetworkAccess]
               [-Credential PSCredential] [-SessionOption PSSessionOption] [CommonParameters]

      Enter-PSSession [-VMId] Guid [-ConfigurationName string] -Credential PSCredential  [CommonParameters]

      Enter-PSSession [-VMName] string [-ConfigurationName string] -Credential PSCredential [CommonParameters]

      Enter-PSSession [-ContainerId] string [-ConfigurationName string] [-RunAsAdministrator]  [CommonParameters]

      Enter-PSSession [[-Id] int] [CommonParameters]

      Enter-PSSession [-InstanceId Guid] [CommonParameters]

      Enter-PSSession [-Name string] [CommonParameters]

      Enter-PSSession [[-Session] PSSession] [CommonParameters]

Key
   -AllowRedirection
       Allow redirection of this connection to an alternate Uniform Resource Identifier (URI).

       When you use -ConnectionURI, the remote destination can return an instruction to redirect to
       a different URI. By default, PowerShell does not redirect connections.

       You can also limit the number of times that the connection is redirected by setting the
       MaximumConnectionRedirectionCount property of the $PSSessionOption preference variable, or the
       MaximumConnectionRedirectionCount property of the value of the SessionOption parameter.
       The default value is 5. For more information, see New-PSSessionOption.

    -ApplicationName string
       The application name segment of the connection URI. Use -ApplicationName to specify the
       application name when you are not using -ConnectionURI.

       The default value is the value of the $PSSessionApplicationName preference variable on
       the local computer. If this variable is not defined, the default value is WSMAN.
       This value is appropriate for most uses. For more information, see about_Preference_Variables.

       The WinRM service uses the application name to select a listener to service the connection request.
       The value of this parameter should match the value of the URLPrefix property of a listener on
       the remote computer.

   -Authentication Authentication
       The authentication mechanism to be used at the server. Possible values are:
        
        Basic      Send username and password in clear text.
        Default    Use the authentication method implemented by WS-Management protocol. This is the default.
        Digest     Challenge-response scheme using a server-specified data string for the challenge.
        Kerberos   Authenticate by using Kerberos certificates.
        Negotiate  Challenge-response that negotiates an authentication scheme.
                    e.g. Kerberos protocol or NTLM.
        NegotiateWithImplicitCredential   Use the credentials cached on the PSSession computer.
        CredSSP    Use Credential Security Service Provider (CredSSP) authentication, delegate
                   credentials to a remote computer. This increases the security risk, if the remote 
                   computer is compromised, the credentials could be used to control the network session.
                   (Windows Vista or later versions.)

   -CertificateThumbprint string
       The certificate thumbprint of the digital public key certificate (X509) of a user account
       that has permission to perform this action.

       Certificates are used in client certificate-based authentication.
       They can be mapped only to local user accounts; they do not work with domain accounts.

       To get a certificate thumbprint, use the Get-Item or Get-ChildItem command
       in the PowerShell Cert: drive.

   -ComputerName string
       Start an interactive session with the specified remote computer.
       A fully qualified domain name, NetBIOS name, or an IP address.
       Use the local computer name, localhost, or a dot (.) to specify the local computer.

       To use an IP address in the value of the ComputerName parameter, the command must include the
       Credential parameter. Also, the computer must be configured for HTTPS transport or the IP address
       of the remote computer must be included in the WinRM TrustedHosts list on the local computer.
       For more see Help about_Remote_Troubleshooting.

       Note:  In Windows Vista and later versions of Windows, to include the local computer in the value
       of the -ComputerName parameter, you must start PowerShell with the "Run as administrator" option.

       The local computer is the default. You can pipe a value for ComputerName.
       When the remote computer is in a different domain, use a fully qualified domain name. 

   -ConfigurationName string
       The session configuration that is used for the interactive session.
       Enter a configuration name or the fully qualified resource URI for a session configuration.
       If you specify only the configuration name, the following schema URI is prepended:
          http://schemas.microsoft.com/powershell.

       The session configuration for a session is located on the remote computer.
       If the specified session configuration does not exist on the remote computer, the command fails.

       The default value is the value of the $PSSessionConfigurationName preference variable on the local computer.
       If this preference variable is not set, the default is Microsoft.PowerShell.
       For more information, see about_Preference_Variables.

    -ConnectionURI Uri
        Specifies a Uniform Resource Identifier (URI) that defines the connection endpoint for the
        interactive session. The URI must be fully qualified. 

        The format of this string is as follows: 
            Transport://ComputerName:Port/ApplicationName
        The default value is as follows:
            http://localhost:5985/WSMAN

        Valid values for the Transport segment of the URI are HTTP and HTTPS.
        If you do not specify a ConnectionURI, you can use the UseSSL, ComputerName, Port, and
        ApplicationName parameters to specify the URI values.

        If the destination computer redirects the connection to a different URI, PowerShell will prevent
        the redirection unless you use -AllowRedirection in the command.

   -Credential PSCredential
       A user account that has permission to perform this action. default=current user.
       e.g. "User64", "Domain01\User64", or "User@Domain.com". Or a PSCredential object, such as 
       returned by Get-Credential. When you type a user name, you will be prompted for a password.

   -Id int
       The ID of an existing session. (from Get-PSSession)
       Enter-PSSession uses the specified session for the interactive session.

   -InstanceId Guid
       The instance ID of an existing session. Enter-PSSession will then use the
       specified session for the interactive session.
       The instance ID is a GUID. To find the instance ID of a session, use Get-PSSession.
       You can also use the Session, Name, or ID parameters to specify an existing session.
       Or, you can use the ComputerName parameter to start a temporary session.

   -Name string
       The friendly name of an existing session. Enter-PSSession will then use the
       specified session for the interactive session.
       If the name that you specify matches more than one session, the command fails.
       You can also use the Session, InstanceID, or ID parameters to specify an existing session.
       Or, you can use the ComputerName parameter to start a temporary session.
       To establish a friendly name for a session, use the Name parameter of New-PSSession.

    -Port int
       The network port on the remote computer used for this command.
       The default is port 80 (the HTTP port).
       Before using an alternate port, configure the WinRM listener on the remote computer to listen at that
       port. Use the following commands to configure the listener:
        1. winrm delete winrm/config/listener?Address=*+Transport=HTTP
        2. winrm create winrm/config/listener?Address=*+Transport=HTTP @{Port="port-number"}
       Do not use the Port parameter unless you must. The port setting in the command applies to
       all computers or sessions on which the command runs.
       An alternate port setting might prevent the command from running on all computers.

   -Session PSSession
       A Windows PowerShell session (PSSession) to use for the interactive session.
       This parameter takes a session object.
       You can also use the Name, InstanceID, or ID parameters to specify a PSSession.
       Enter a variable that contains a session object or a command that creates or gets a
       session object, such as New-PSSession or Get-PSSession.
       Session objects may also be piped to Enter-PSSession.
       Submit only one PSSession with this parameter. If you enter a variable that contains more
       than one PSSession, the command fails.
       Exit-PSSession or the EXIT keyword, will end the interactive session, but the PSSession
       that you created remains open and available for use.

   -SessionOption PSSessionOption
       Set advanced options for the session. Enter a SessionOption object that you create
       using New-PSSessionOption.
       The default values for the options are determined by the value of the $PSSessionOption
       preference variable, if it is set. Otherwise, the session uses the system defaults.
       For information about the $PSSessionOption preference variable, see about_Preference_Variables.

   -UseSSL
       Use the Secure Sockets Layer (SSL) protocol to establish a connection to the remote computer.
       By default, SSL is not used.
       WS-Management encrypts all Windows PowerShell content transmitted over the network.
       UseSSL is an additional protection that sends the data across an HTTPS connection instead of
       an HTTP connection.
       If you use this parameter, but SSL is not available on the port used for the command, the command fails.

Standard Aliases for Enter-PSSession: etsn

By default only administrators or members of the built-in local security group Remote Management Users are allowed to create new PowerShell sessions and remotely execute commands. In practice you would create a global group to manage the membership.

It is also possible to grant access by changing the session configuration - this would be useful if you need to quickly grant a single non-admin user access to PowerShell Remoting on a single machine without requiring the user to log off.

Enter-PSSession starts an interactive session with a single remote computer. During the session, the commands that you type run on the remote computer, just as though you were typing directly on the remote computer. You can have only one interactive session at a time.

Use -ComputerName to specify the name of the remote computer or reconnect to a session previously setup with New-PSSession.

To end the interactive session and disconnect from the remote computer, use Exit-PSSession, or type "exit".

Examples

Start an interactive session on the local computer. The command prompt changes to indicate that you are now running in a different session:

PS C:> Enter-PSSession

List processes running on server64 and create a log file on the remote server:

PS C:> enter-pssession -computer Server64
Server64\PS> get-process powershell > C:\ps-test\process.txt
Server01\PS> exit-pssession

Connect to server svrDNS1 and load the Active Directory Module, the module does not need to be installed on the client (run the server copy):

PS C:> PS C:\powershell> Enter-PSSession "svrDNS1"
[serverDNS1]: PS C:\Users\simon\Documents> Import-Module ActiveDirectory
[serverDNS1]: PS C:\Users\simon\Documents> Set-Location AD:
[serverDNS1]: PS AD:\>

Connect to the users $logonserver:

PS C:> PS C:\powershell> Enter-PSSession ($env:logonserver).replace("\\","")

“The real test of friendship is: can you literally do nothing with the other person? Can you enjoy those moments of life that are utterly simple?” - Eugene Kennedy

Related PowerShell Cmdlets

How-To: Run a powershell script on a remote computer.
Exit-PSSession - End an interactive session with a remote computer.
New-PSSession - Create a persistent connection to a local or remote computer.
Invoke-Command - Run a single command on local or remote computer.


 
Copyright © 1999-2024 SS64.com
Some rights reserved