Simple example
function do-something {
param (
[validateSet('foo', 'bar', 'baz')] [string] $doWhat
)
switch ($doWhat) {
'foo' { write-host 'Foo!' }
'bar' { write-host 'Bar!' }
'baz' { write-host 'Baz!' }
}
}
Invoking this function with a value that doesn't belong to the list results in an error message:
PS: > do-something xyz
do-something : Cannot validate argument on parameter 'doWhat'. The argument "xyz" does not belong to the set "foo,bar,baz"
specified by the ValidateSet attribute. Supply an argument that is in the set and then try the command again. …