I am using switch parameters in my PowerShell script in this fashion.
param(
[switch] $Word,
[switch] $Excel,
[switch] $powerpoint,
[switch] $v2007,
[switch] $v2010,
[switch] $x86,
[switch] $x64,
)
I am trying to figure out any neat way to have it more enum style.
As anyone might guess, I would want the user to choose between word, excel and powerpoint.
And between x2007 and v2010.
Is there a neat way to get input params enum style?
I am new to PowerShell. So if this sounds like that I don’t know something obvious, then please point me to some link where I can read about it.
I would use a
ValidateSetparameter attribute instead.From: about_Functions_Advanced_Parameters
Example function:
Output:
test-value : Cannot validate argument on parameter 'Application'. The argument "foo" does not belong to the set "word,excel,powerpoint" specified by the ValidateSet attribute. Supply an argument that is in the set and then try the command again.