ValidateSet
noun
say it: “VAL-uh-dayt set” /ˈvælədeɪt sɛt/
A rule above a PowerShell parameter that allows only the values in a short list, and lets Tab offer them.
What does ValidateSet do?
[ValidateSet()] limits a parameter to a short list of values. Anything else stops with an error that lists the allowed ones, and Tab offers them as you type, so a typo like Chil never gets in.
param(
[ValidateSet('Chill', 'Upbeat', 'Focus')]
[string]$Mood
)
# Add-Song -Mood Chil stops: The argument "Chil" does not belong to the set "Chill,Upbeat,Focus" ...
In a sentence
- “ValidateSet turned the typo Chil into a clear error.”
- “With ValidateSet, typing -Mood and pressing Tab offered Chill, Upbeat and Focus.”
Level: Journeyman · More PowerShell terms at this level
Updated