Freigeben über


Parameter HelpMessage Arguement

I taught a PowerShell course the other day. I hadn't delivered that content for a while. I came to a section and I couldn't remember exactly how to access the configured functionality. One of those moments!

After, I thought the experience would make for an interesting little post and here we are...

Look at this:

 [CmdletBinding()]
Param ([parameter(mandatory,
HelpMessage="Enter one or more users names separated by commas.")]
[String[]]$UserName) 

The Param() statement let's us define parameters for a script or function. We can also supply arguments to the parameter attribute. In the above example, mandatory ensures that that particular parameter must be used. HelpMessage, unsurprisingly, lets you define a help message for that parameter.

Now, how and when do you get to see that help message!?

Capture158

 

If I run the little block of code, due to the mandatory argument, I get asked to supply a value to UserName. But, look at this - ' (Type !? for Help.) ' - it was that simple little statement that escaped me!

Ok, I type !? and we get the help message defined by HelpMessage.

Cool.

PS - the memory lapse wasn't because I'm getting old... honest!

Comments

  • Anonymous
    July 08, 2016
    Always interestingThanks