0
0
PowerShellscripting~10 mins

Verbose and debug output in PowerShell - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Verbose and debug output
Start Script
Set VerbosePreference
Set DebugPreference
Run Commands
If Verbose enabled
Show Verbose Messages
If Debug enabled
Show Debug Messages
End Script
The script sets preferences for verbose and debug output, then runs commands that may produce messages shown only if those preferences are enabled.
Execution Sample
PowerShell
Write-Verbose "Starting script"
Write-Debug "Debug info"
Write-Output "Normal output"
This script writes verbose and debug messages plus normal output; verbose and debug messages show only if enabled.
Execution Table
StepCommandVerbosePreferenceDebugPreferenceVerbose OutputDebug OutputNormal Output
1Write-Verbose "Starting script"ContinueContinueStarting script
2Write-Debug "Debug info"ContinueContinueDebug info
3Write-Output "Normal output"ContinueContinueNormal output
4Write-Verbose "Starting script"SilentlyContinueSilentlyContinue
5Write-Debug "Debug info"SilentlyContinueSilentlyContinue
6Write-Output "Normal output"SilentlyContinueSilentlyContinueNormal output
7End of scriptSilentlyContinueSilentlyContinue
💡 Script ends after all commands run; verbose and debug outputs depend on preference settings.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4After Step 5After Step 6Final
VerbosePreferenceContinueContinueContinueContinueSilentlyContinueSilentlyContinueSilentlyContinueSilentlyContinue
DebugPreferenceContinueContinueContinueContinueSilentlyContinueSilentlyContinueSilentlyContinueSilentlyContinue
Verbose OutputStarting scriptStarting scriptStarting script
Debug OutputDebug infoDebug info
Normal OutputNormal outputNormal outputNormal outputNormal outputNormal output
Key Moments - 3 Insights
Why do verbose messages sometimes not show even if Write-Verbose is used?
Verbose messages only show if VerbosePreference is set to 'Continue' or higher. See execution_table rows 1 and 4 where preference changes affect output.
What controls whether debug messages appear?
Debug messages appear only if DebugPreference is set to 'Continue'. In the table, rows 2 and 5 show debug output present or absent based on this.
Does Write-Output depend on Verbose or Debug preferences?
No, Write-Output always shows normal output regardless of VerbosePreference or DebugPreference, as seen in rows 3 and 6.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table row 2. What is the Debug Output at this step?
ANo output
BStarting script
CDebug info
DNormal output
💡 Hint
Check the 'Debug Output' column in row 2 of the execution_table.
At which step does the Verbose Output stop showing messages?
AStep 3
BStep 4
CStep 1
DStep 6
💡 Hint
Look at the VerbosePreference change and corresponding Verbose Output in rows 3 and 4.
If DebugPreference is set to 'SilentlyContinue', what happens to debug messages?
AThey do not show
BThey show normally
CThey show only once
DThey appear as errors
💡 Hint
Refer to Debug Output in rows 5 and 6 where DebugPreference is 'SilentlyContinue'.
Concept Snapshot
Write-Verbose and Write-Debug send messages shown only if VerbosePreference or DebugPreference is 'Continue'.
Set preferences with $VerbosePreference and $DebugPreference.
Write-Output always shows output.
Use verbose/debug to help see script details without cluttering normal output.
Full Transcript
This lesson shows how PowerShell scripts can produce extra messages for debugging or verbose info. The script sets preferences controlling if these messages appear. Write-Verbose messages show only if VerbosePreference is 'Continue'. Write-Debug messages show only if DebugPreference is 'Continue'. Normal output from Write-Output always shows. The execution table traces commands step-by-step, showing when messages appear or not depending on preferences. Variables track preference changes and outputs. Key moments clarify why messages may not appear and how preferences control them. The quiz tests understanding of when verbose and debug messages show. This helps beginners see how to add helpful script messages that can be turned on or off easily.