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!