Bird
0
0

Why is it important to use [ValidateSet()] with [Parameter(Mandatory=$true)] in PowerShell functions?

hard📝 Conceptual Q10 of 15
PowerShell - Functions
Why is it important to use [ValidateSet()] with [Parameter(Mandatory=$true)] in PowerShell functions?
ATo make the parameter optional and accept any value
BTo ensure the parameter is provided and only valid values are accepted
CTo allow null values and skip validation
DTo automatically convert parameter types
Step-by-Step Solution
Solution:
  1. Step 1: Understand Mandatory attribute purpose

    It forces the user to provide the parameter value.
  2. Step 2: Understand ValidateSet attribute purpose

    It restricts the parameter to accept only specific valid values.
  3. Step 3: Combine both for input safety

    Together, they ensure the parameter is always provided and valid.
  4. Final Answer:

    To ensure the parameter is provided and only valid values are accepted -> Option B
  5. Quick Check:

    Mandatory + ValidateSet = required and valid input [OK]
Quick Trick: Mandatory + ValidateSet ensures required valid input [OK]
Common Mistakes:
  • Thinking Mandatory makes parameter optional
  • Assuming ValidateSet allows any value
  • Believing these attributes convert types automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes