Powertip Of The Day-make function parameters mandatory

Source: Internet
Author: User

Original article address:Http://app.en25.com/e/es.aspx? S = 1403 & E = 5441 & elq = 3d32771b868b437aa97567a6a50b5563

Original article:

Mandatory parameters are special because if you do not submit it, powershell will automatically ask for it. you can use mandatory parameters in your own functions as well. you shoshould simply mark a function as mandatory by adding the appropriate [parameter ()] attribute like so:

Function Test-me {
Param (
[ Parameter ( Mandatory = $ True )]
$ Name
)
"You entered $ name ."
}

Test-me

The parameter attributes used in this tip were introduced with powershell V2.

 

 

Translation:

MandatoryThe parameter is special because this parameter is not submitted,PowershellIt will automatically let you enter. You can also use it in your own functions.MandatoryParameters. You only need to mark[Parameter ()]You can mark the attribute before the method, for example:

Function Test-me {
Param (
[ Parameter ( Mandatory = $ True )]
$ Name
)
"You entered $ name ."
}

Test-me

This parameter attribute is used inPowershell v2Has been introduced.

 

 

Notes:

MandatoryThe meaning of the corresponding Chinese characters here is not very clear, forced? Obligation? Mandatory?

The last sentence is not very understandable.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.