对不起,你不能。 -Debug
是一个常用参数,因此-Debug
和-db
是几乎包括您自己编写的函数在内的所有可用交换机。正如错误告诉你的那样,它已经被定义了。
即使有可能绕过去取消定义内置别名,即unexpectantly改变别人像test-db -db
呼叫谁经常使用-db
而不是-Debug
意义。他们期望它启用调试输出,而不是指定不同的参数。
考虑一下这个功能:
function test-db{
param(
[parameter(mandatory=$true)]
[string]$database)
write-host 'database' $database
write-debug 'debugging output'
}
现在有了test-db server
,test-db -db server
和test-db server -db
调用它。第一个不做write-debug
,而另外2个做,不管-db
是哪里。你也不能定义一个单独的参数[string]$db
(或重命名$database
到$db
),因为PowerShell的给你这个错误:
Parameter 'db' cannot be specified because it conflicts with the parameter alias of the same name for parameter 'Debug'.
更多信息这一点,每MSDN:
In addition to using the AliasAttribute attribute, the Windows PowerShell runtime performs partial name matching, even if no aliases are specified. For example, if your cmdlet has a FileName parameter and that is the only parameter that starts with F, the user could enter Filename, Filenam, File, Fi, or F and still recognize the entry as the FileName parameter.
这应该工作。听起来你有两个(或更多)具有相同别名的参数。 – Richard