PowerShell Logo Small

Enter-PSSession



This is the built-in help made by Microsoft for the command 'Enter-PSSession', in PowerShell version 4 - as retrieved from Windows version 'Microsoft Windows 8.1 Enterprise' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Starts an interactive session with a remote computer.

SYNTAX


Enter-PSSession [-ComputerName] <String> [-ApplicationName <String>] [-Authentication <AuthenticationMechanism>] [-CertificateThumbprint <String>] [-ConfigurationName
<String>] [-Credential <PSCredential>] [-EnableNetworkAccess] [-Port <Int32>] [-SessionOption <PSSessionOption>] [-UseSSL] [<CommonParameters>]
Enter-PSSession [[-ConnectionUri] <Uri>] [-AllowRedirection] [-Authentication <AuthenticationMechanism>] [-CertificateThumbprint <String>] [-ConfigurationName <String
>] [-Credential <PSCredential>] [-EnableNetworkAccess] [-SessionOption <PSSessionOption>] [<CommonParameters>]
Enter-PSSession [[-Id] <Int32>] [<CommonParameters>]
Enter-PSSession [-InstanceId <Guid>] [<CommonParameters>]
Enter-PSSession [-Name <String>] [<CommonParameters>]
Enter-PSSession [[-Session] <PSSession>] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


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


Typically, you use the ComputerName parameter to specify the name of the remote computer. However, you can also use a session that you create by using the New-PSSessi
on cmdlet for the interactive session. However, you cannot use the Disconnect-PSSession, Connect-PSSession, or Receive-PSSession cmdlets to disconnect from or re-conn
ect to an interactive session.


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



<

RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/p/?linkid=289578
Exit-PSSession
Get-PSSession
Invoke-Command
New-PSSession
Remove-PSSession
Connect-PSSession
Disconnect-PSSession
Receive-PSSession
about_PSSessions
about_Remote

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

PS C:\>Enter-PSSession
[localhost]: PS C:\>



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

The commands that you enter run in the new session, and the results are returned to the default session as text.






-------------------------- EXAMPLE 2 --------------------------

The first command uses the Enter-PSSession cmdlet to start an interactive session with Server01, a remote computer. When the session starts, the command prompt change
s to include the computer name.
PS C:\>Enter-PSSession -Computer Server01
[Server01]: PS C:\>

The second command gets the PowerShell process and redirects the output to the Process.txt file. The command is submitted to the remote computer, and the file is save
d on the remote computer.
[Server01]: PS C:\>Get-Process Powershell > C:\ps-test\Process.txt

The third command uses the Exit keyword to end the interactive session and close the connection.
[Server01]: PS C:\>exit
PS C:\>

The fourth command confirms that the Process.txt file is on the remote computer. A Get-ChildItem ("dir") command on the local computer cannot find the file.
PS C:\>dir C:\ps-test\process.txt
Get-ChildItem : Cannot find path 'C:\ps-test\process.txt' because it does not exist.
At line:1 char:4
+ dir <<<< c:\ps-test\process.txt



This command shows how to work in an interactive session with a remote computer.




-------------------------- EXAMPLE 3 --------------------------

PS C:\>$s = New-PSSession -ComputerName Server01
PS C:\>Enter-PSSession -Session $s
[Server01]: PS C:\>



These commands use the Session parameter of Enter-PSSession to run the interactive session in an existing Windows PowerShell session (PSSession).






-------------------------- EXAMPLE 4 --------------------------

PS C:\>Enter-PSSession -ComputerName Server01 -Port 90 -Credential Domain01\User01
[Server01]: PS C:\>



This command starts an interactive session with the Server01 computer. It uses the Port parameter to specify the port and the Credential parameter to specify the acco
unt of a user with permission to connect to the remote computer.






-------------------------- EXAMPLE 5 --------------------------

PS C:\>Enter-PSSession -ComputerName Server01
[Server01]: PS C:\>Exit-PSSession
PS C:\>



This example shows how to start and stop an interactive session. The first command uses the Enter-PSSession cmdlet to start an interactive session with the Server01 c
omputer.

The second command uses the Exit-PSSession cmdlet to end the session. You can also use the Exit keyword to end the interactive session. Exit-PSSession and Exit have t
he same effect.