Bird
0
0

What will be the output of this script when called with -Level "Medium"?

medium📝 Command Output Q4 of 15
PowerShell - Scripting Best Practices
What will be the output of this script when called with -Level "Medium"?
function Test-Level {
  param(
    [ValidateSet('Low','Medium','High')]
    [string]$Level
  )
  Write-Output "Level is $Level"
}
Test-Level -Level "Medium"
ALevel is Medium
BLevel is Low
CError: Invalid argument for -Level
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Check parameter validation

    [ValidateSet('Low','Medium','High')] allows only these three values for $Level.
  2. Step 2: Analyze input and output

    The input "Medium" is valid, so the function outputs Level is Medium.
  3. Final Answer:

    Level is Medium -> Option A
  4. Quick Check:

    Valid value in ValidateSet outputs normally [OK]
Quick Trick: ValidateSet blocks invalid values, valid ones print output [OK]
Common Mistakes:
  • Expecting error for valid input
  • Confusing output with default value
  • Assuming no output on valid input

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes