我的脚本开头有以下 Param 块:
Param
(
[Parameter(Mandatory = $true)]
[ValidateScript({Test-Path $_ -PathType Leaf})]
[string]$Config,
[switch]$OverThresholdOnly,
[switch]$SendEmail,
[switch]$Debug
)
当我运行脚本时,我收到错误:
"A parameter with the name 'Debug' was defined multiple times for this command. At line:1 char:1"
Line:1 and char:1 is the start of the Param block.
如果我将 $Debug 更改为 $Verbose,我会收到关于 Verbose 的相同错误。我尝试将 $debug 放在 Param 块的顶部,但出现相同的错误。
如果我删除 [ValidateScript] 部分,它工作正常。
谁能告诉我为什么会这样?为什么 [ValidateScript] 使用 $Debug 以及如何绕过重命名变量?