question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mandatory param HelpMessage not working in Powershell 7.2.7

See original GitHub issue

Prerequisites

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:closed
  • Created a year ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
237dmitrycommented, Oct 26, 2022

I think this behavior was always. The same is in Windows PowerShell. Enter !? and get help message.

1reaction
garretwilsoncommented, Oct 26, 2022

Seems like other experts …

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

about Functions Advanced Parameters - PowerShell
The Mandatory argument indicates that the parameter is required. If this argument isn't specified, the parameter is optional. The following ...
Read more >
More PowerShell Parameter Planning
[Parameter(Position = 0, HelpMessage = 'Specify the folder to analyze.')] I am not making it mandatory because I will set a default value....
Read more >
PowerShell HelpMessage displayed by default in parameters
I used this line in a PS script: param( [Parameter(Mandatory=$true)] [string] $ResourceGroup = $(Read-Host -Prompt "Enter the Resource Group ...
Read more >
A Helpful Message about HelpMessage
It works only on mandatory (required) parameters. When you omit a mandatory parameter, you get a message like this one: PS C:\> Get- ......
Read more >
How to make the HelpMessage parameter attribute display ...
When the user fails to provide the mandatory parameter I want them to receive the help message and I swear there was a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found