liveBook · Manning

Run Selection

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

Run Selection is a Visual Studio Code editor action that executes selected PowerShell code, or the current line when no code is selected.

Run Selection is a Visual Studio Code action for testing PowerShell code a piece at a time. It sends the selected code, or the current line when nothing is selected, to the PowerShell Integrated Console. section 25.2

Use it to inspect a script while it runs:

  • Open a .ps1 file in Visual Studio Code and place the cursor on a line. section 25.2
  • Click Run Selection (F8) to execute the current line. section 25.2
  • Highlight several lines and click the same button to execute exactly that selection. section 25.2
  • Inspect variables in the integrated console after execution; their values persist, revealing script state as it changes. section 25.2

Run a process query incrementally

Run `$processName = 'pwsh'`, then run `Get-Process $processName`. Change the variable to `code*` and run the query again to observe a different process set.

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

How deep it goes
Explains current-line and selection execution, then demonstrates persistent state; it stops short of extension internals.
Examples
Demonstrates Write-Host, a process-name variable, and Get-Process queries in Visual Studio Code.
What it assumes
Assumes a .ps1 file, Visual Studio Code, and the PowerShell extension; teaches the execution workflow directly.
What you can do after
Diagnose/debug PowerShell scripts by executing lines or selections and inspecting resulting state immediately.
How it connects
Connects PowerShell scripts with debugging, variables, and the PowerShell Integrated Console.

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.