Recall & Review
beginner
What does the
Mandatory attribute do in a PowerShell parameter?The
Mandatory attribute makes a parameter required. PowerShell will ask the user to provide a value if it is not supplied when running the script or function.Click to reveal answer
beginner
What is the purpose of the
ValidateSet attribute in PowerShell parameters?The
ValidateSet attribute restricts the parameter's input to a predefined list of allowed values. This helps prevent errors by limiting choices to valid options.Click to reveal answer
intermediate
How do you define a mandatory parameter named
Color that only accepts 'Red', 'Green', or 'Blue'?Use
[Parameter(Mandatory=$true)][ValidateSet('Red','Green','Blue')]$Color in the parameter block to make it required and limit choices.Click to reveal answer
beginner
What happens if a user provides a value not in the
ValidateSet list?PowerShell throws an error and stops execution, telling the user the value is invalid and showing the allowed options.
Click to reveal answer
beginner
Can you combine
Mandatory and ValidateSet attributes on the same parameter?Yes, combining them ensures the parameter is required and only accepts specific values from the set.
Click to reveal answer
What does the
Mandatory attribute do in a PowerShell parameter?✗ Incorrect
The
Mandatory attribute forces the user to provide a value for the parameter.Which attribute restricts a parameter's input to a fixed list of values?
✗ Incorrect
ValidateSet limits input to a predefined set of allowed values.What will happen if a user omits a parameter marked as
Mandatory?✗ Incorrect
PowerShell prompts the user to enter a value for mandatory parameters if missing.
If a parameter has
ValidateSet('Red','Green','Blue'), what happens if the user inputs 'Yellow'?✗ Incorrect
PowerShell throws an error because 'Yellow' is not in the allowed set.
How do you make a parameter both required and limited to specific values?
✗ Incorrect
Combining both attributes makes the parameter required and restricts its values.
Explain how the
Mandatory and ValidateSet attributes work together in PowerShell parameters.Think about forcing the user to choose from specific options.
You got /3 concepts.
Describe what happens when a user runs a script without providing a mandatory parameter that has a ValidateSet.
Consider the user experience when input is missing or wrong.
You got /3 concepts.