[Enum[]] [array] ValidateSet .
function SomethingSomethingAuthType {
param(
[parameter(Mandatory=$true,position=0)]
[AllowNull()]
[AllowEmptyCollection()]
[AuthType[]] $authTypes
)
Write-Host 'Made it past validation.'
if(!$authTypes) { return }
$authTypes | % {
Write-Host "type: $_" -f Green
}
}
# Check if the enum exists, if it doesn't, create it.
if(!("AuthType" -as [Type])){
Add-Type -TypeDefinition @'
public enum AuthType{
anonymousAuthentication,
basicAuthentication,
clientCertificateMappingAuthentication,
digestAuthentication,
iisClientCertificateMappingAuthentication,
windowsAuthentication
}
'@
}
# Testing
# =================================
SomethingSomethingAuthType $null # will pass
SomethingSomethingAuthType anonymousAuthentication, basicAuthentication # will pass
SomethingSomethingAuthType invalid # will fail
SomethingSomethingAuthType anonymousAuthentication, invalid, broken # will fail