Bird
0
0

Identify the error in this parameter declaration:

medium📝 Debug Q7 of 15
PowerShell - Functions
Identify the error in this parameter declaration:
param(
  [Parameter(Mandatory)]
  [ValidateSet('On','Off')]
  $Switch
)
AParameter attribute cannot be used with ValidateSet
BValidateSet values must be numeric
CMandatory attribute missing =true or $true
DParameter name must be capitalized
Step-by-Step Solution
Solution:
  1. Step 1: Check Mandatory attribute syntax

    The Mandatory attribute requires an explicit value like = $true. Just Mandatory is invalid.
  2. Step 2: Validate other options

    ValidateSet accepts strings, Parameter and ValidateSet can be combined, and parameter names are case-insensitive.
  3. Final Answer:

    Mandatory attribute missing =true or $true -> Option C
  4. Quick Check:

    Mandatory needs explicit true value [OK]
Quick Trick: Always write Mandatory=$true, not just Mandatory [OK]
Common Mistakes:
  • Omitting =true in Mandatory
  • Thinking ValidateSet only accepts numbers
  • Believing parameter names must be capitalized

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes