[Parameter (Mandatory=$False)]
[ValidateSet("Val1", "Val2", "Val3", "Val4", "Val5",ignorecase=$true)]
[string[]] $configs = ""
Is there a way to alter the above so that I can accept several of the enum values in one go?
I'm hoping to be able to launch the script as so:
.\MyAwesome-Script.ps1 -config Val1 Val2 (or any combination of enum values as parameters)
But I need this to also be tab complete-able (is that even a word?)
For completeness, I'm using PS 4.0 and PSCX 3.1 is also installed
Just make your variable an array and it'll work just fine. Given the following function:
function Test-ValidateSet
{
PARAM(
[ValidateSet("Val1", "Val2", "Val3")]
[string[]]$MyParam
)
foreach($value in $MyParam)
{
Write-Host "Parameter given: $value"
}
}
For the above method, I get tab-completion on the MyParam parameter. To enter an array for the parameter, just separate the values with comma characters.
Test-ValidateSet -MyParam Val1, Val2, Val3
This supports tab-completion in both the PowerShell console and the PowerShell ISE.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With