Enter-PSSession opens a one-to-one interactive PowerShell session with a local or remote computer. The prompt changes to show the computer you control, so commands run there until you leave the session. section 13.5 section 18.2
Connect directly by naming the destination:
- Use -ComputerName for a Windows destination, such as Enter-PSSession -ComputerName SRV2 -UserName contoso\tylerl. section 13.5
- Use -HostName for a host such as Ubuntu1, optionally supplying a user name. section 13.5
- Run Exit-PSSession, or use exit, to return to the local prompt. section 13.5
Enter an existing session
Create or retrieve a session, then pass one PSSession object to Enter-PSSession: $session = New-PSSession -ComputerName localhost; Enter-PSSession $session; Get-Process; Exit-PSSession. Exiting ends the interactive shell but leaves the PSSession open for later commands. section 18.2 section 18.7
Enter-PSSession -HostName Ubuntu1 -UserName tylerl Enter-PSSession -ComputerName SRV2 -UserName contoso\tylerl
Browse copyable Enter-PSSession commands for Ubuntu and Windows destinations. section 13.5
The -Session parameter accepts one session object from a variable, New-PSSession, or Get-PSSession. You can also pipe a single session to Enter-PSSession; a variable containing multiple sessions must be narrowed first. section 18.2
Avoid starting another Enter-PSSession from inside a remote session unless a deliberate hop is required. Otherwise, chained connections become harder to track and add unnecessary server overhead. section 13.5
