Bird
0
0

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

easy📝 Conceptual Q2 of 15
PowerShell - Functions
Which attribute restricts a PowerShell parameter to accept only specific predefined values?
A[ValidateSet()]
B[AllowNull()]
C[ValidateRange()]
D[Parameter(Mandatory=$true)]
Step-by-Step Solution
Solution:
  1. Step 1: Identify the attribute for value restriction

    The [ValidateSet()] attribute limits parameter input to a set of allowed values.
  2. Step 2: Eliminate other attributes

    [Parameter(Mandatory=$true)] enforces presence, [ValidateRange()] restricts numeric ranges, and [AllowNull()] allows nulls.
  3. Final Answer:

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

    ValidateSet = restrict to specific values [OK]
Quick Trick: Use ValidateSet to limit parameter choices [OK]
Common Mistakes:
  • Confusing Mandatory with ValidateSet
  • Using ValidateRange for string values
  • Assuming AllowNull restricts values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes