liveBook · Manning

Enter-PSSession

As explained in Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS

Enter-PSSession is a PowerShell cmdlet that creates an interactive session with a local or remote computer.

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

How Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS covers it

How deep it goes
Explains direct connections, session objects, exit behavior, pipeline input, and remote-chaining cautions.
Examples
Demonstrates Ubuntu and Windows connections, prompt changes, process inspection, session reuse, and session cleanup.
What it assumes
Assumes basic PowerShell command use and distinguishes interactive sessions from reusable PSSession objects.
What you can do after
Operate a remote interactive shell, reuse an existing session, and return safely to the local prompt.
How it connects
Connects interactive remoting with PSSession, New-PSSession, Get-PSSession, Exit-PSSession, and Invoke-Command.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS. The section links point to the parts of the book it draws on.