क्षमा करें, आप नहीं कर सकते। -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
परिभाषित कर सकते हैं (या $db
को $database
नाम बदलने) क्योंकि 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.
स्रोत
2011-07-29 14:01:38
यह काम करना चाहिए। लगता है जैसे आपके पास समान उपनाम वाले दो (या अधिक) पैरामीटर हैं। – Richard