對不起,你不能。 -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