I have 2 class-based argument completers/validate sets for 2 of my PowerShell module's parameters.
[ValidateSet([PolicyIDz])][parameter(Mandatory = $false, ParameterSetName = "Remove Policies")][string[]]$PolicyIDs,
[ValidateSet([PolicyNamez])][parameter(Mandatory = $false, ParameterSetName = "Remove Policies")][string[]]$PolicyNames,
# argument tab auto-completion and ValidateSet for Policy names
Class PolicyNamez : System.Management.Automation.IValidateSetValuesGenerator {
[string[]] GetValidValues() {
$PolicyNamez = ((CiTool -lp -json | ConvertFrom-Json).Policies | Where-Object { $_.IsSystemPolicy -ne "True" }).Friendlyname
return [string[]]$PolicyNamez
}
}
# argument tab auto-completion and ValidateSet for Policy IDs
Class PolicyIDz : System.Management.Automation.IValidateSetValuesGenerator {
[string[]] GetValidValues() {
$PolicyIDz = ((CiTool -lp -json | ConvertFrom-Json).Policies | Where-Object { $_.IsSystemPolicy -ne "True" }).policyID
return [string[]]$PolicyIDz
}
}
They are for Windows Defender Application Control and if you want to try it you need at least Windows 11 22H2 which has CITool built-in.
I want to have both validate set and argument completion for each of those parameters, and on top of that, prevent argument completer from suggesting the same values that I've already selected. I'm using latest PowerShell 7.4 version. Both of those parameters are used in the same cmdlet.
Remove-WDACConfig [-RemovePolicies] [-PolicyIDs <String[]>] [-PolicyNames <String[]>]
This question is related to another one I asked previously (and got answers).
This is the current behavior I'm trying to change