Bird
0
0

You have this function:

medium📝 Debug Q6 of 15
PowerShell - Functions
You have this function:
function Test-Param {
  param(
    [Parameter(Mandatory=$true)]
    [ValidateSet('Yes','No')]
    $Answer
  )
  Write-Output $Answer
}

When calling Test-Param without arguments, what error occurs?
ANo error, $Answer defaults to null
BError: Missing mandatory parameter 'Answer'
CError: Invalid parameter value
DFunction runs but outputs empty string
Step-by-Step Solution
Solution:
  1. Step 1: Check Mandatory attribute effect

    Mandatory=$true requires the parameter to be provided; omitting it causes an error.
  2. Step 2: ValidateSet does not affect missing parameter error

    The error is about missing parameter, not invalid value.
  3. Final Answer:

    Error: Missing mandatory parameter 'Answer' -> Option B
  4. Quick Check:

    Mandatory missing = error [OK]
Quick Trick: Mandatory parameters must be supplied or error occurs [OK]
Common Mistakes:
  • Assuming missing parameter defaults to null
  • Confusing missing parameter with invalid value error
  • Expecting function to run without arguments

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes