This guide shows you how to use PowerShell’s built-in verbose and debug streams to get more detail from your scripts and commands. You’ll learn how to write scripts that emit these streams, how to turn them on when you run a command, and how to control where the output goes. No prior knowledge beyond basic PowerShell usage is needed.
What You’ll Need
- PowerShell 5.1 or later (most Windows 10/11 systems have this).
- Windows PowerShell or PowerShell 7 (both work the same for these features).
- A script or command you want to add verbose/debug output to.
Step-by-Step
- Understand the streams. PowerShell has six output streams: Success (normal output), Error, Warning, Verbose, Debug, and Information. Verbose and Debug are hidden by default; you must explicitly enable them to see them.
- Write verbose messages in your script. Use
Write-Verbose "Your message here"to add detailed progress or diagnostic info. For example:Write-Verbose "Processing file $file". These messages are only shown when the-Verboseparameter is used. - Write debug messages in your script. Use
Write-Debug "Your debug message"for even more granular, developer-oriented details. For example:Write-Debug "Variable value: $var". These are shown when-Debugis used, and they trigger a prompt asking if you want to continue (unless$DebugPreferenceis set toContinue). - Run a command with verbose output. For any cmdlet that supports it, add
-Verboseto the command line. Example:Get-Process -Verbose. This shows the verbose stream from that cmdlet. - Run a command with debug output. Add
-Debugto the command line. Example:Get-Process -Debug. This shows debug messages and prompts you to continue after each one. - Control the behavior with preference variables. Set
$VerbosePreferenceand$DebugPreferencetoContinueto always show output, orSilentlyContinueto suppress it. For example:$VerbosePreference = 'Continue'. This affects all commands in the current session. - Redirect verbose and debug streams to a file. Use
4>> verbose.logfor verbose and5>> debug.logfor debug. Example:Get-Process -Verbose 4>> verbose.log. This appends the verbose stream to the file. - Use
[CmdletBinding()]to add-Verboseand-Debugto your own functions. At the top of your function, add[CmdletBinding()]before theparam()block. This automatically gives your function the common parameters, including-Verboseand-Debug. - Test your script with both switches. Run your script with
-Verboseand then with-Debugto see the different levels of detail. Adjust yourWrite-VerboseandWrite-Debugmessages so they are useful at each level.
Common Mistakes
- Using
Write-Hostinstead ofWrite-Verbose.Write-Hostalways displays output and cannot be suppressed. UseWrite-Verbosefor optional detail. - Forgetting that
-Verboseand-Debugare not available on all commands. They are only present on advanced functions (those with[CmdletBinding()]) and many built-in cmdlets. Simple scripts without that attribute won’t have them. - Not setting
$DebugPreferencewhen running non-interactively. If you run a script with-Debugin a scheduled task or CI pipeline, the prompt will hang. Set$DebugPreference = 'Continue'at the top of the script to avoid this. - Mixing up stream redirection numbers. Remember: 1 is success, 2 is error, 3 is warning, 4 is verbose, 5 is debug, and 6 is information. Using the wrong number will not capture the stream you want.
Tips
- Use
Write-Verbosefor progress andWrite-Debugfor state. Verbose should describe what the script is doing (e.g., “Copying file…”), while Debug should reveal variable values and logic decisions (e.g., “File exists: True”). - Make verbose messages informative but not noisy. A good rule is: if a user running with
-Verbosewould be annoyed by the message, put it inWrite-Debuginstead. - Use the
-Verboseparameter on your own functions by default. It costs nothing and makes your scripts much easier to troubleshoot. - Combine
-Verbosewith-ErrorActionto get more context on failures. For example,Get-Content -Verbose -ErrorAction Stopwill show verbose output and stop on the first error. - In PowerShell 7, you can use
6>>for information stream, but verbose and debug are still 4 and 5. Keep this in mind if you’re writing cross-version scripts.
Troubleshooting
- Verbose output is not showing even with
-Verbose. Check if the command is a simple function or script without[CmdletBinding()]. Add[CmdletBinding()]to your function. Also check if$VerbosePreferenceis set toSilentlyContinuein your profile—override it with$VerbosePreference = 'Continue'. - Debug output prompts and hangs. This is normal when
$DebugPreferenceisInquire(the default). To avoid prompts, set$DebugPreference = 'Continue'at the start of your script or before running the command. - Redirection to a file creates an empty file. Make sure you’re using the correct stream number. For verbose, use
4>>and for debug, use5>>. Also ensure the command actually produces verbose/debug output—some cmdlets are silent even with-Verbose. - Your own function doesn’t accept
-Verbose. Add[CmdletBinding()]beforeparam(). If you’re using a script file, also add[CmdletBinding()]to the script’sparam()block. - Verbose output appears but is not formatted nicely. By default, verbose messages are prefixed with “VERBOSE:”. That’s normal. If you want to control formatting, use
Write-Hostwith a custom color, but remember that’s not suppressible.
Frequently Asked Questions
- What’s the difference between
Write-VerboseandWrite-Debug? Verbose is for high-level progress information that a user might want to see. Debug is for low-level details that help a developer diagnose issues. Debug also triggers a prompt by default, while verbose does not. - Can I use
-Verboseon any cmdlet? No, only on advanced functions and cmdlets that explicitly support it. Most built-in cmdlets do, but simple scripts or functions without[CmdletBinding()]do not. - How do I make verbose output always show for a script? Set
$VerbosePreference = 'Continue'at the top of the script. This will show allWrite-Verbosemessages without needing the-Verboseswitch. - Can I redirect verbose output to a file without affecting normal output? Yes, use
4>> file.log. For example,Get-Process -Verbose 4>> verbose.logwill only write the verbose stream to the file, while normal output goes to the console. - Why does
-Debugask me to continue? Because the default$DebugPreferenceisInquire, which prompts on each debug message. Set$DebugPreference = 'Continue'to automatically continue without prompting. - Is there a way to see both verbose and debug at the same time? Yes, you can pass both
-Verboseand-Debugto a command, or set both preference variables toContinue. The output will interleave, which can be noisy but gives full detail.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Omega ORU52X Specs: What They Mean for You42.00 cu ft
- AI Agent State Safety During Context Compaction
- Games Like Assassin’s Creed: 12 Open-World Picks
- KCD2 Blacksmith’s Son Quest Guide
- Snapdragon 6s Gen 3 vs 665: Which Is Faster?
- Delete Stations Pandora? How to Remove Them