0
0
PowerShellscripting~20 mins

Verbose and debug output in PowerShell - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Verbose & Debug Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this PowerShell script with verbose enabled?
Consider this script run with the -Verbose flag:
function Test-Verbose {
  [CmdletBinding()] 
  param()
  Write-Verbose "Starting process"
  Write-Output "Process running"
  Write-Verbose "Process completed"
}

Test-Verbose -Verbose

What will be printed to the console?
PowerShell
function Test-Verbose {
  [CmdletBinding()] 
  param()
  Write-Verbose "Starting process"
  Write-Output "Process running"
  Write-Verbose "Process completed"
}

Test-Verbose -Verbose
ANo output
BProcess running
C
VERBOSE: Starting process
Process running
VERBOSE: Process completed
D
VERBOSE: Starting process
VERBOSE: Process completed
Attempts:
2 left
💡 Hint
Verbose messages appear only when the -Verbose flag is used.
💻 Command Output
intermediate
2:00remaining
What happens when you use Write-Debug without enabling debug?
Given this script:
function Test-Debug {
  [CmdletBinding()] 
  param()
  Write-Debug "Debug info"
  Write-Output "Normal output"
}

Test-Debug

What will be the output?
PowerShell
function Test-Debug {
  [CmdletBinding()] 
  param()
  Write-Debug "Debug info"
  Write-Output "Normal output"
}

Test-Debug
ADEBUG: Debug info
B
DEBUG: Debug info
Normal output
CNo output
DNormal output
Attempts:
2 left
💡 Hint
Debug messages show only when debug preference is enabled.
📝 Syntax
advanced
2:00remaining
Which option correctly enables debug output in a PowerShell script?
You want to see debug messages from Write-Debug in your script. Which code snippet correctly enables debug output?
A
$DebugPreference = 'Continue'
Write-Debug "Debug message"
B
Set-Debug -Enable
Write-Debug "Debug message"
C
Enable-Debug
Write-Debug "Debug message"
D
$DebugMode = $true
Write-Debug "Debug message"
Attempts:
2 left
💡 Hint
PowerShell uses a preference variable to control debug message display.
🚀 Application
advanced
2:00remaining
How to capture verbose output into a variable in PowerShell?
You want to run a command and save its verbose messages into a variable for later use. Which approach works?
A$verboseOutput = Get-Process -Verbose 4>&1
B$verboseOutput = Get-Process -Verbose | Out-String
C$verboseOutput = & { Get-Process -Verbose 4>&1 }
D$verboseOutput = Get-Process -Verbose 3>&1
Attempts:
2 left
💡 Hint
Verbose messages are sent to stream 4 in PowerShell.
🧠 Conceptual
expert
2:00remaining
What is the effect of setting $VerbosePreference to 'SilentlyContinue'?
In PowerShell, what happens if you set:
$VerbosePreference = 'SilentlyContinue'

and then run a script that uses Write-Verbose?
AVerbose messages are always shown regardless of -Verbose flag.
BVerbose messages are suppressed and not shown.
CVerbose messages cause an error.
DVerbose messages are shown only if -Verbose flag is used.
Attempts:
2 left
💡 Hint
The preference variable controls how verbose messages behave.