I've got a method that needs to accept an array of strings as a parameter, but that array can only contain valid strings. My problem is that if I ensure to [AllowNull()], and also [AllowEmptyCollection()], the method still fails
function SomethingSomethingAuthType {
param(
[parameter(Mandatory=$true,position=0)]
[ValidateSet('anonymousAuthentication','basicAuthentication','clientCertificateMappingAuthentication','digestAuthentication','iisClientCertificateMappingAuthentication','windowsAuthentication')]
[AllowNull()]
[AllowEmptyCollection()]
[array] $authTypes
)
$authTypes | % {
Write-Host $_ -f Green
}
}
SomethingSomethingAuthType $null
SomethingSomethingAuthType : Cannot validate argument on parameter 'authTypes'. The argument is null, empty, or an element of the argument collection contains a null value. Supply a collection that does not contain any null values and then try the command again. At line:16 char:32 + SomethingSomethingAuthType $null + ~~~~~ + CategoryInfo : InvalidData: (:) [SomethingSomethingAuthType], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,SomethingSomethingAuthType
What do I need to do to allow $null to be passed in, but also validate the set to ensure the appropriate types?