Couldn't use predefined array inside Validateset - Powershell
7
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:
$vf = @('Veg', 'Fruit')
function Test-ArgumentCompleter {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)]
[ValidateSet($vf)]
$Arg
)
}
The expected result should be: When writing 'Test-ArgumentCompleter F', after clicking the tub button the F autocompleted to Fruit. Thanks in advance for your help!
powershell validateset
[ValidateSet('Veg','Fruit')]
– Theo May 2 at 13:22ValidateScript
where you test yourself if the input var is found in an array, but then you lose intellisense. – Theo May 2 at 13:50