【发布时间】:2013-01-08 19:48:52
【问题描述】:
例如,我的脚本可以这样调用:
.\MyScript.ps1 -s <hostname1>
如果我在没有使用 -s 参数传递参数的情况下调用它,我会收到错误:
.\MyScript.ps1 -s
C:\MyScript.ps1 : Missing an argument for parameter 'sql'. Specify a pa
rameter of type 'System.String' and try again.
At line:1 char:18
+ .\MyScript.ps1 -s <<<<
+ CategoryInfo : InvalidArgument: (:) [MyScript.ps1], ParameterBindingException
+ FullyQualifiedErrorId : MissingArgument,MyScript.ps1
有什么办法可以抑制这个错误,或者让自定义错误出现:
.\MyScript.ps1 -s
Please pass a hostname with the s argument:
.\MyScript.ps1 -s <hostname>
【问题讨论】:
标签: powershell parameters arguments parameter-passing powershell-2.0