Mandatory param HelpMessage not working in Powershell 7.2.7
See original GitHub issuePrerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
The parameters documentation says that if a mandatory parameter is missing, the help message is shown as a prompt. (Various web sites imply this as well.)
The
HelpMessage
argument specifies a string that contains a brief description of the parameter or its value. PowerShell displays this message in the prompt that appears when a mandatory parameter value is missing from a command.
I’m a PowerShell newbie, but “PowerShell displays this message in the prompt that appears when a mandatory parameter value is missing from a command” is pretty unambiguous. It says that 1) if there is a mandatory parameter, and 2) the value is missing, then 3) the specified help message will be displayed, and 4) that help message will be displayed at the prompt that appears asking for the missing value. I’m not sure how I could be misinterpreting that.
This is the example given in the official documentation, verbatim:
Param(
[Parameter(Mandatory,
HelpMessage="Enter one or more computer names separated by commas.")]
[string[]]
$ComputerName
)
Expected behavior
PS> .\test-param-help-message.ps1
Enter one or more computer names separated by commas.
Actual behavior
PS> .\test-param-help-message.ps1
cmdlet test-param.ps1 at command pipeline position 1
Supply values for the following parameters:
(Type !? for Help.)
ComputerName[0]:
Error details
No response
Environment data
Name Value
---- -----
PSVersion 7.2.7
PSEdition Core
GitCommitId 7.2.7
OS Microsoft Windows 10.0.19044
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Visuals
No response
Issue Analytics
- State:
- Created a year ago
- Comments:7 (2 by maintainers)
I think this behavior was always. The same is in Windows PowerShell. Enter
!?
and get help message.Hahah. Sorry, @mklement0, when I referred to your other comment I didn’t realize I was replying to you. I didn’t look closely and thought your reply was also from @kilasuit as was the earlier one. Oops.
Have a great day both of you.