Identify parameter

function MyArgumentCompleter{
    param ( $commandName,
            $parameterName,
            $wordToComplete,
            $commandAst,
            $fakeBoundParameters )

$fruit = @('Apple', 'Orange', 'Banana')
$Vegetables = @('Onion', 'Carrot', 'Lettuce')
    


    $possibleValues = $fruit +$Vegetables

        $possibleValues | Where-Object {
            $_ -like "$wordToComplete*"
        }|foreach-object{"$_"}
 
}

Class food : System.Management.Automation.IValidateSetValuesGenerator {
    [string[]] GetValidValues() {
$fruit = @('Apple', 'Orange', 'Banana')
$Vegetables = @('Onion', 'Carrot', 'Lettuce')
$food =$fruit +$Vegetables
        return [string[]] $food
    }
}
function Test-ArgumentCompleter {
[CmdletBinding()]
 param (
        [validateset([food])]
        [Parameter(Mandatory=$true)]
        [ArgumentCompleter({ MyArgumentCompleter @args })]
        $food
      


      )
}

so as you can see ,the $food has two type ,but since i didn’t use $type to define it and combine the fruit and vegetable ,it can’t tell if i am input $fruit or $vegtable,so is there any way to let powershell define the $food is fruit or vegetable with variable ?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.