PowerShell Logo Small

Set-PSDebug



This is the built-in help made by Microsoft for the command 'Set-PSDebug', in PowerShell version 5 - as retrieved from Windows version 'Microsoft Windows Server 2012 R2 Standard' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

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

SYNTAX


Set-PSDebug [-Off] [<CommonParameters>]
Set-PSDebug [-Step] [-Strict] [-Trace [<Int32>]] [<CommonParameters>]



Search powershellhelp.space

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.



<

RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/p/?linkid=289612
Debug-Process
Set-PSBreakpoint
Set-StrictMode
Write-Debug
about_Debuggers

REMARKS

<

Examples


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

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



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










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

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



This command turns on stepping and then

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










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

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



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










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

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 <<<<



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