How to Step Over, Step Into, and Step Out While Debugging

Use the following information to debug a script by stepping through it.

Stepping is the process of running one statement at a time. You can stop on a line of code, and examine the values of variables and the state of the system. The following table describes common debugging tasks such as stepping over, stepping into, and stepping out.

Debugging Task

Description

How to accomplish it in PowerShell ISE

Step Into

Executes the current statement and then stops at the next statement. If the current statement is a function or script call, then the debugger steps into that function or script, otherwise it stops at the next statement.

In the Command Pane, type S and press ENTER, or, on the Debug menu, click Step Into.

Step Over

Executes the current statement and then stops at the next statement. If the current statement is a function or script call then the debugger executes the whole function or script, and it stops at the next statement after the function call.

In the Command Pane, type V and press ENTER, or, on the Debug menu, click Step Over.

Step Out

Steps out of the current function and up one level if the function is nested. If in the main body, the script is executed to the end, or to the next breakpoint. The skipped statements are executed, but not stepped through.

In the Command Pane, type O and press ENTER, or, on the Debug menu, click Step Out.

Continue

Continues execution to the end, or to the next breakpoint. The skipped functions and invocations are executed, but not stepped through.

In the Command Pane, type C and press ENTER, or, on the Debug menu, click Run/Continue.

Debugging a script

  1. Set the breakpoints in the code you want to examine. For information about how to set breakpoints, see How to Set, Remove, Disable Enable, Disable, and List Breakpoints or Set-PSBreakpoint.

  2. On the Debug menu, click Run/Continue, or on the toolbar, click Run Script. Here is what you can expect:

    • Debugging starts. The script runs until it locates the first breakpoint and then stops. The breakpoint is highlighted.

    • The command prompt changes, and the prefix [DBG] appears on the Command Pane bar.

    • A message about the breakpoint that was encountered appears in the Output Pane. For example, “Hit Line breakpoint on 'C:\Users\name\Desktop\test.script.ps1:13”.

    The message contains the script name and details about the line breakpoint, variable breakpoint, or command breakpoint.

  3. From here you may step over, step into, step out, or continue. Continue causes the debugger to execute to the end of the script or to the next breakpoint.

  4. To find the value of a variable while you are debugging, hover over the variable in the Script Pane, or type the variable name in the Command Pane, and press ENTER. The Output Pane displays the value of the variable. Continue to step through the script, or perform other debugging tasks.

See Also