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:

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

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!?



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.


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




Comments (1)

  1. Always interesting

Skip to main content