Write Debug - PowerShell


The Write-Debug cmdlet outputs debug messages to the debug stream. These messages can be helpful for troubleshooting scripts and understanding the flow of execution.


Write-Debug [-Message] <string> [[-Category] <string>] [[-Source] <string>]


  • -Message: (Required) Specifies the debug message to output.
  • -Category: (Optional) Specifies the category of the debug message. Valid categories are:
    • Default (default)
    • Error
    • Warning
    • Success
    • Information
    • Verbose
  • -Source: (Optional) Specifies the source of the debug message.


Simple Example

Write-Debug "This is a debug message."

Specify Category

Write-Debug "This is a warning message." -Category Warning

Specify Source

Write-Debug "This message is from the Get-ChildItem cmdlet." -Source Get-ChildItem

Common Issues

  • Message not output: Ensure the -Message parameter is specified and contains a valid string.
  • Category not recognized: Use one of the valid categories listed in the Options/Flags section.


The Write-Debug cmdlet can be used together with other PowerShell commands to provide detailed tracing information. For example, the following script uses Write-Debug to output the results of each iteration of a loop:

1..10 | ForEach-Object {
    $i = $_
    Write-Debug "Iteration $i"
  • Trace-Command: Traces all commands in a script and outputs detailed information to the debug stream.
  • Get-Command: Retrieves information about specified commands, including their aliases, parameters, and scripts.