Couldn’t use predefined array inside Validateset – Powershell

Question:

I’m looking for a way to make a cmdlet which receives parameter and while typing, it prompts suggestions for completion from a predefined array of options.

I was trying something like this:

The expected result should be:
When writing ‘Test-ArgumentCompleter F’, after clicking the tub button, the F autocompleted to Fruit.

Answer:

To complement the answers from @mklement0 and @Mathias, using dynamic parameters:

Depending on how you want to predefine you argument values, you might also use dynamic validateSet values:

note: The IValidateSetValuesGenerator class [read: interface] was introduced in PowerShell 6.0

Source:

Couldn’t use predefined array inside Validateset – Powershell by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply