Turns script debugging features on and off.

      Set-PSDebug [-trace int] [-step] [-strict] [CommonParameters]

      Set-PSDebug [-off] [CommonParameters]

   -trace int
       Set the trace level:
          0 - Off
          1 - trace script lines as they are executed
          2 - trace script lines, variable assignments, function calls and scripts.

       Turn on script stepping. Before each line is run, PowerShell will prompt
       to stop, continue or enter a new interpreter level to inspect the state
       of the script. (Step automatically sets Trace =1)

       Throw an exception if a variable is referenced before being assigned a value.

       Turn off all debugging features.


Set the trace level to 2:

PS C:\> set-psdebug -trace 2;

Turns stepping on:

PS C:\> set-psdebug -step

Turn off all debugging features:

PS C:\> set-psdebug -off

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it" ~ Brian W. Kernighan

Related PowerShell Cmdlets

Write-Debug - Write a debug message to the host display.
Set-StrictMode - Enforce coding rules in expressions & scripts.
Equivalent bash command: set -x / +x - turn debug on/off, or bash -x

Copyright © 1999-2024
Some rights reserved