Export (0) Print
Expand All
1 out of 2 rated this helpful - Rate this topic

Write-Debug

Updated: October 17, 2013

Applies To: Windows PowerShell 4.0

Write-Debug

Writes a debug message to the console.

Syntax

Parameter Set: Default
Write-Debug [-Message] <String> [ <CommonParameters>]




Detailed Description

The Write-Debug cmdlet writes debug messages to the console from a script or command.

By default, debug messages are not displayed in the console, but you can display them by using the Debug parameter or the $DebugPreference variable.

Parameters

-Message<String>

Specifies the debug message to send to the console.


Aliases

none

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

true (ByValue)

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.

  • System.String

    You can pipe a string that contains a debug message to Write-Debug.


Outputs

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

  • None

    Write-Debug writes only to the debug stream. It does not return any output.


Examples

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

This command writes a debug message. Because the value of $DebugPreference is "SilentlyContinue", the message is not displayed in the console.


PS C:\> Write-Debug "Cannot open file."

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

This example shows how to use the Debug common parameter to override the value of the $DebugPreference variable for a particular command.

The first command displays the value of the $DebugPreference variable, which is "SilentlyContinue", the default.

The second command writes a debug message but, because of the value of $DebugPreference, the message does not appear.

The third command writes a debug message. It uses the Debug common parameter to override the value of $DebugPreference and to display the debug messages resulting from this command.

As a result, even though the value of $DebugPreference is "SilentlyContinue", the debug message appears.

For more information about the Debug common parameter, see about_CommonParameters.


PS C:\> $DebugPreference
SilentlyContinue
PS C:\>Write-Debug "Cannot open file."
PS C:\>
PS C:\>Write-Debug "Cannot open file." -debug
DEBUG: Cannot open file.

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

This command shows the effect of changing the value of the $DebugPreference variable on the display of debug messages.

The first command displays the value of the $DebugPreference variable, which is "SilentlyContinue", the default.

The second command writes a debug message but, because of the value of $DebugPreference, the message does not appear.

The third command assigns a value of "Continue" to the $DebugPreference variable.

The fourth command writes a debug message, which appears on the console.

For more information about $DebugPreference, see about_Preference_Variables.


PS C:\> $DebugPreference
SilentlyContinue
PS C:\>Write-Debug "Cannot open file."
PS C:\>
PS C:\>$DebugPreference = "Continue"
PS C:\>Write-Debug "Cannot open file."
DEBUG: Cannot open file.

Related topics



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

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.