1
當函數參數使用驗證集時,我似乎無法使splatting工作。使用ValidateSet PowerShell Splatting
下面的例子產生以下錯誤:
WhichFruit : Cannot validate argument on parameter 'fruit'. The argument "System.Collections.Hashtable" does not belong to the set "Apple,Orange" specified by the ValidateSet attribute. Supply an argument that is in the set and then try the command again.
Function WhichFruit {
param(
[ValidateSet("Apple","Orange")]
[string]$fruit
)
Write-Host $fruit
}
$params = @{ fruit = "Apple" }
WhichFruit $params