Tracing and Debugging

The three facilities for tracing and debugging in PowerShell are the Set-PsDebug cmdlet, the Trace-Command cmdlet, and verbose cmdlet output.

The Set-PsDebug Cmdlet

The Set-PsDebug cmdlet allows you to control tracing, stepping, and strict mode in PowerShell.

Parameters of the Set-PsDebug cmdlet

Parameter

Description

Trace

Sets the amount of tracing detail that PowerShell outputs when running commands.

A value of 1 outputs all lines as PowerShell evaluates them. A value of 2 outputs all lines as PowerShell evaluates them, along with information about variable assignments, function calls, and scripts. A value of 0 disables tracing.

Step

Enables and disables per-command stepping. When enabled, PowerShell prompts you before it executes a command.

Strict

Enables and disables strict mode. When enabled, PowerShell throws a terminating error if you attempt to reference a variable that you have not yet defined.

Off

Turns off tracing, stepping, and strict strict mode.

The Trace-Command Cmdlet

Trace-Command CommandDiscovery -PsHost { gci c: }

The Trace-Command cmdlet exposes diagnostic and support information for PowerShell commands. PowerShell groups its diagnostic information into categories called Trace Sources.

A full list of trace sources is available through the Get-TraceSource cmdlet.

For more information about the Trace-Command cmdlet, type Get-Help Trace-Command.

Verbose Cmdlet Output

<Cmdlet> -Verbose

PowerShell commands can generate verbose output using the Write-Verbose cmdlet (if written as a script,) or the WriteVerbose() API (when written as a cmdlet.)

The $VerbosePreference automatic variable allows you to control how PowerShell handles verbose output. It supports the following values:

VerbosePreference automatic variable values

Value

Meaning

SilentlyContinue

Do not display verbose output. This is the default

Stop

Treat verbose output as a terminating error.

Continue

Display verbose output and continue execution of the current cmdlet, script, function, or pipeline.

Inquire

Display a prompt that asks how PowerShell should treat this verbose output.

Most cmdlets allow you to configure this explicitly by passing one of the above values to its Verbose parameter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.25.32