Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Set-PSDebug

Updated: October 17, 2013

Applies To: Windows PowerShell 4.0

Set-PSDebug

Turns script debugging features on and off, sets the trace level, and toggles strict mode.

Syntax

Parameter Set: off
Set-PSDebug [-Off] [ <CommonParameters>]

Parameter Set: on
Set-PSDebug [-Step] [-Strict] [-Trace <Int32> ] [ <CommonParameters>]




Detailed Description

The Set-PSDebug cmdlet turns script debugging features on and off, sets the trace level, and toggles strict mode.

When the Trace parameter is set to 1, each line of script is traced as it is executed. When the parameter is set to 2, variable assignments, function calls, and script calls are also traced. If the Step parameter is specified, you are prompted before each line of the script is executed.

Parameters

-Off

Turns off all script debugging features.

Note: A "set-strictmode -off" command disables the verification set by a "set-psdebug -strict" command. For more information, see Set-StrictMode.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Step

Turns on script stepping. Before each line is run, the user is prompted to stop, continue, or enter a new interpreter level to inspect the state of the script.

Note: Specifying the Step parameter automatically sets a Trace level of 1.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Strict

Specifies that the interpreter should throw an exception if a variable is referenced before a value is assigned to the variable.

Note: A "set-strictmode -off" command disables the verification set by a "set-psdebug -strict" command. For more information, see Set-StrictMode.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Trace<Int32>

Specifies the trace level:

0 - Turn script tracing off

1 - Trace script lines as they are executed

2 - Trace script lines, variable assignments, function calls, and scripts.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see  about_CommonParameters (http://go.microsoft.com/fwlink/p/?LinkID=113216).

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.

  • None

    You cannot pipe input to this cmdlet.


Outputs

The output type is the type of the objects that the cmdlet emits.

  • None

    This cmdlet does not return any output.


Examples

-------------------------- EXAMPLE 1 --------------------------

This command sets the trace level to 2, and then runs a script that displays the numbers 1, 2, and 3.


PS C:\> set-psdebug -trace 2; foreach ($i in 1..3) {$i}

DEBUG:    1+ Set-PsDebug -trace 2; foreach ($i in 1..3) {$i}
DEBUG:    1+ Set-PsDebug -trace 2; foreach ($i in 1..3) {$i}
1
DEBUG:    1+ Set-PsDebug -trace 2; foreach ($i in 1..3) {$i}
2
DEBUG:    1+ Set-PsDebug -trace 2; foreach ($i in 1..3) {$i}
3

-------------------------- EXAMPLE 2 --------------------------

This command turns on stepping and then

runs a script that displays the numbers 1, 2, and 3.


PS C:\> set-psdebug -step; foreach ($i in 1..3) {$i}

DEBUG:    1+ Set-PsDebug -step; foreach ($i in 1..3) {$i}
Continue with this operation?
1+ Set-PsDebug -step; foreach ($i in 1..3) {$i}
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help
(default is "Y"):a
DEBUG:    1+ Set-PsDebug -step; foreach ($i in 1..3) {$i}
1
2
3

-------------------------- EXAMPLE 3 --------------------------

This command turns off all debugging features, and then runs a script that displays the numbers 1, 2, and 3.


PS C:\> set-psdebug -off; foreach ($i in 1..3) {$i}
1
2
3

-------------------------- EXAMPLE 4 --------------------------

This command puts the interpreter in strict mode, and attempts to access a variable that has not yet been set.


PS C:\> set-psdebug -strict; $NewVar
The variable $NewVar cannot be retrieved because it has not been set yet.
At line:1 char:28
+ Set-PsDebug -strict;$NewVar <<<<

Related topics


Debug-Process

Set-PSBreakpoint

Set-StrictMode

Write-Debug

about_Debuggers



Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.