locked
Using HelpMessage in Parameter Attributes RRS feed

  • Question

  • I am attempting to use the HelpMessage attribute for my PowerShell parameters, however, when I am prompted for the parameters while running my PowerShell script, I do not see any Help Message that provides insight about what to enter for my parameters.

    [CmdletBinding()]
    Param(
    [Parameter(Mandatory=$True,HelpMessage="Please enter the SQL sysadmin username", Position=1)]
    [string]$SQLUsername
    )
    

    How do I get Help information that informs the user what to enter for a particular parameter when they are prompted for a particular parameter?

    Please advise.

    Wednesday, November 4, 2015 5:01 PM

Answers

  • You're not going to see the option to show the help message unless someone doesn't enter a value for your mandatory -SQLUsername parameter. And even if they don't enter a value, they're going to have to enter !? to actually be presented with your help message. Take a look at the image I've included when running jrv's function.

    jrv's idea to use the ValidateSet attribute is a nice option to display the acceptable values from this parameter, by using Tab. Also be sure to include comment-based help, so users can run Get-Help against your function and find out what you function requires. Help messages are nice, but they are often not included because full and complete comment-based help, to include some examples, is where people should go that need assistance using a function or cmdlet.

    • Marked as answer by vs2015junkie Thursday, November 5, 2015 3:15 AM
    Wednesday, November 4, 2015 5:53 PM

All replies

  • Use auto-complete with "ValidateSet"

    function Test-Param{
    	[CmdletBinding()]
    		Param(
    			[ValidateSet('Admin1','Admin2','Admin3')]
    			[Parameter(
    				Mandatory=$True,
    				HelpMessage="Please enter the SQL sysadmin username",
    				Position=1
    			)][string]$SQLUsername
    		)
    }
    
    Test-Admin -SQLUsername <tab>

    Just hit <tab> to fill in.


    \_(ツ)_/

    Wednesday, November 4, 2015 5:11 PM
  • You're not going to see the option to show the help message unless someone doesn't enter a value for your mandatory -SQLUsername parameter. And even if they don't enter a value, they're going to have to enter !? to actually be presented with your help message. Take a look at the image I've included when running jrv's function.

    jrv's idea to use the ValidateSet attribute is a nice option to display the acceptable values from this parameter, by using Tab. Also be sure to include comment-based help, so users can run Get-Help against your function and find out what you function requires. Help messages are nice, but they are often not included because full and complete comment-based help, to include some examples, is where people should go that need assistance using a function or cmdlet.

    • Marked as answer by vs2015junkie Thursday, November 5, 2015 3:15 AM
    Wednesday, November 4, 2015 5:53 PM