Bird
0
0

You wrote this parameter declaration:

medium📝 Debug Q14 of 15
PowerShell - Functions
You wrote this parameter declaration:
param(
  [Parameter(Mandatory=$true)]
  [ValidateSet('Small','Medium','Large')]
  [string]$Size
)

But when running the script without the -Size argument, it does not prompt for input and continues silently. What is the likely cause?
AThe parameter type should be [int] instead of [string].
BThe script is missing <code>CmdletBinding()</code> to enable parameter validation.
CMandatory parameters never prompt for input automatically.
DThe ValidateSet attribute is incorrect and disables Mandatory.
Step-by-Step Solution
Solution:
  1. Step 1: Understand Mandatory prompt behavior

    Mandatory parameters prompt for input only if the function or script uses CmdletBinding() or is an advanced function.
  2. Step 2: Identify missing CmdletBinding()

    Without CmdletBinding(), the script treats parameters as simple variables and does not enforce Mandatory prompts.
  3. Final Answer:

    The script is missing CmdletBinding() to enable parameter validation. -> Option B
  4. Quick Check:

    CmdletBinding() enables Mandatory prompts [OK]
Quick Trick: Add CmdletBinding() to enable Mandatory prompts [OK]
Common Mistakes:
  • Thinking ValidateSet disables Mandatory
  • Assuming Mandatory never prompts
  • Changing parameter type unnecessarily

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes