Files
Resolve-DSCConfigurationData/Private/Assert-ConfigurationDataParameterAllowedValue.ps1

38 lines
1013 B
PowerShell

function Assert-ConfigurationDataParameterAllowedValue {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)]
[string]
$Name,
[Parameter(Mandatory=$true)]
$Definition,
[AllowNull()]
$Value
)
if(-not (Test-ConfigurationDataMapContainsKey -Map $Definition -Key "AllowedValues")){
return
}
$AllowedValues = @(Get-ConfigurationDataMapValue -Map $Definition -Key "AllowedValues")
if($AllowedValues.Count -eq 0){
return
}
if($Value -is [System.Array] -and $Value -isnot [string]){
foreach($Item in @($Value)){
if($AllowedValues -notcontains $Item){
throw "Parameter [$Name] value [$Item] is not allowed. Allowed values are: $($AllowedValues -join ', ')."
}
}
return
}
if($AllowedValues -notcontains $Value){
throw "Parameter [$Name] value [$Value] is not allowed. Allowed values are: $($AllowedValues -join ', ')."
}
}