liveBook · Manning

Exit-PSSession

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

Exit-PSSession is a PowerShell cmdlet that ends the current interactive PowerShell session and returns to the originating shell.

Exit-PSSession ends the current interactive PowerShell remoting session and returns the prompt to the originating shell. It requires no parameters; after running it, the remote connection closes automatically. section 13.5

Leave an interactive session

After working on a remote computer, run:\n\nExit-PSSession\n\nThe prompt changes back to its normal local form. If the PowerShell window closes first, the connection closes automatically as well. section 13.5

Keep these remoting points in mind:

  • Use Exit-PSSession as the counterpart to Enter-PSSession when finishing one-to-one remoting. section 13.5
  • Avoid starting another Enter-PSSession from inside a remote session unless a deliberate second hop is required. 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 syntax, prompt behavior, automatic connection closure, and a remote-chaining caution.
Examples
Uses an Exit-PSSession command after interactive remote administration and contrasts it with closing the PowerShell window.
What it assumes
Assumes familiarity with entering an interactive remoting session through Enter-PSSession.
What you can do after
Operate/configure an interactive remoting session by leaving it cleanly with Exit-PSSession.
How it connects
Connects interactive remoting with Enter-PSSession, remote sessions, and second-hop behavior.

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.