Bird
0
0

Which parameter validation attribute restricts a parameter to accept only specific values in PowerShell?

easy📝 Conceptual Q2 of 15
PowerShell - Scripting Best Practices
Which parameter validation attribute restricts a parameter to accept only specific values in PowerShell?
A[ValidateLength()]
B[ValidateRange()]
C[ValidatePattern()]
D[ValidateSet()]
Step-by-Step Solution
Solution:
  1. Step 1: Identify attribute purpose

    [ValidateSet()] restricts parameter values to a predefined set of allowed values.
  2. Step 2: Eliminate other options

    [ValidateRange()] restricts numeric ranges, [ValidatePattern()] uses regex, and [ValidateLength()] limits string length.
  3. Final Answer:

    [ValidateSet()] -> Option D
  4. Quick Check:

    Restrict values to set = [ValidateSet()] [OK]
Quick Trick: Use [ValidateSet()] to allow only specific values [OK]
Common Mistakes:
  • Confusing [ValidateRange()] with [ValidateSet()]
  • Using regex attribute for fixed values
  • Assuming [ValidateLength()] restricts values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes