On this page

Debugging Tools in VS Code

Enrico Hochkoeppler Profile

By Enrico Hochkoeppler

Web Developer & TutoriaLibre Founder

Visual Studio Code provides a rich, integrated debugging experience for PowerShell. These tools help you inspect variables, step through code, set breakpoints, and understand exactly what your script is doing at runtime. Mastering the VS Code debugger is essential for diagnosing logic errors, unexpected behavior, and complex control‑flow issues.


1. Requirements​

To debug PowerShell scripts in VS Code, you need:

Once the extension is installed, VS Code automatically enables debugging features for .ps1 files.


2. Running a Script in the Debugger​

Open any .ps1 file and press:

When debugging starts, VS Code:


3. Breakpoints​

Breakpoints tell the debugger where to pause execution so you can inspect the state of your script.

3.1 Setting a breakpoint​

Click in the left margin next to a line of code, or press:

A red dot appears, indicating the breakpoint is active.

3.2 Types of breakpoints​

3.3 Conditional breakpoint example​

Right‑click a breakpoint → Edit Breakpoint → add a condition:


$i -eq 5

The debugger pauses only when $i equals 5.


4. Stepping Through Code​

Once the debugger is paused, you can control execution:

ActionShortcutDescriptionContinueF5Resume until next breakpointStep OverF10Run next line, skipping function internalsStep IntoF11Enter function callsStep OutShift+F11Finish current function and return

These controls let you follow the script’s logic line‑by‑line.


5. Inspecting Variables​

The Run and Debug panel shows:

You can expand objects to inspect their properties.

5.1 Hover inspection​

Hover your mouse over a variable:


$items = Get-ChildItem

VS Code displays its current value in a tooltip.

5.2 Debug Console​

The Debug Console lets you run PowerShell commands in the context of the paused script.

Example:


$items.Count

This is extremely useful for inspecting state without modifying the script.


6. Using the Call Stack​

The Call Stack panel shows the chain of function calls that led to the current line.

Example:


Main.ps1 → Process-Data → Validate-Item

You can click any frame to jump to that function’s source code.

This is invaluable when debugging nested functions or modules.


7. Logging and Output Tools​

VS Code integrates with PowerShell’s built‑in logging:

Enable debug/verbose output in the Debug Console:


$DebugPreference = "Continue"

$VerbosePreference = "Continue"

These messages appear in the integrated terminal during debugging.


8. Debugging PowerShell Modules​

When debugging module code:

  1. Open the module folder in VS Code
  2. Press F5 to start a PowerShell debugging session
  3. Import the module manually or via a startup script
  4. Set breakpoints inside module functions

VS Code pauses execution even inside imported modules.


9. Debugging Remote Sessions​

The PowerShell extension supports remote debugging via:

You can debug scripts running on remote machines just like local ones.


10. Summary​

VS Code provides a full suite of debugging tools:

FeaturePurposeBreakpointsPause execution at key pointsStep controlsWalk through code line‑by‑lineVariable inspectionSee script state at runtimeDebug ConsoleRun commands in paused contextCall StackUnderstand function call flowLogging integrationView debug/verbose output

These tools make it dramatically easier to diagnose issues, understand script behavior, and build reliable PowerShell code.

Found this helpful? Share the knowledge...

... or support this project to keep it alive!

Buy Me a Coffee

Previous

ErrorActionPreference

Next

Working with Files, Processes & Services