liveBook · Manning

Breakpoint

As explained in Learn PowerShell Scripting in a Month of Lunches, Second Edition: Write and organize scripts and tools

A breakpoint is a debugger control point at which script execution pauses so the current state can be examined or execution can be stepped or resumed.

A breakpoint pauses script execution at a chosen line so you can inspect variables and properties, step through code, or resume normally. It is a core tool for finding logic bugs. section 23.4.1 section 23.6

Use a breakpoint in VS Code to inspect a script as it runs:

  • Set a breakpoint beside the line where a variable has just been assigned or is about to be used; press F9 to toggle it. section 23.4.1
  • Press F5 to run the script until execution reaches the breakpoint, then examine the highlighted line and Debug pane. section 23.4.1
  • Inspect values in the terminal, use F11 to advance one line, or resume execution with F5. section 23.4.1

Inspecting a disk object

Pause on line 17 after $disk is assigned, then inspect $disk and its DriveType property. Comparing the observed value with the expected string can expose a logic error. section 23.4.1 section 23.4.3

Figure 23.2 Hitting a breakpoint in VS Code

Use the debugger view to recognize the paused line, open the Debug pane, and confirm that execution has reached the breakpoint. section 23.4.1

How Learn PowerShell Scripting in a Month of Lunches, Second Edition: Write and organize scripts and tools covers it

How deep it goes
Explains placement, pausing, inspection, stepping, and resumption, while deferring additional debugger capabilities to help documentation.
Examples
Demonstrates line 17, the $disk variable, DriveType inspection, F9, F5, and F11 in VS Code.
What you can do after
Diagnose/debug PowerShell scripts by pausing execution, inspecting state, stepping through decisions, and comparing expectations with observed values.
How it connects
Connects breakpoints with watches, variables, properties, stepping, and logic-bug debugging.

Also explained in

Compare how 6 books explain breakpoint →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn PowerShell Scripting in a Month of Lunches, Second Edition: Write and organize scripts and tools. The section links point to the parts of the book it draws on.