Example of setting Help information for function parameters in PowerShell _powershell

Source: Internet
Author: User

This article describes how to set help information for a required parameter when you create a custom function in PowerShell.

In the following code, we create a test-function function. This function has a parameter p, which is a required argument. Further, we set a helpmessage attribute for this parameter $p, which means to provide help information for this required parameter. Because it is a required parameter, the function does not execute without entering a value, and prompts for a value for the parameter. If the user does not know what value should be entered for this parameter, then this helpmessage may be helpful.

Copy Code code as follows:

PS c:\users\hong> function Test-function
>> {
>> param (
>> [Parameter (mandatory= $true, helpmessage= ' hahahaha ')]
>> $p
>>)
>> "$p"
>>}
>>
PS c:\users\hong> test-function

Cmdlet test-function at command pipe location 1
Please provide a value for the following parameters:
(Please type!?) to view Help. )
P:!?
Hahahaha
P:

The above should notice, want to see helpmessage information, must in the parameter prompt here input "!?" These two characters.

About the required parameters for the PowerShell function to set Help information, this article on the introduction of so many, I hope to help you, thank you!

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.