0

If I have a parameter like this

  [Parameter(Mandatory=$true, ParameterSetName='InsertException')]
  [Parameter(Mandatory=$true, ParameterSetName='UpdateException')]
  [string]$Requestor = ([Environment]::UserDomainName + '\' + [Environment]::UserName),

When someone runs my script like

.\myscript

the script should prompt him for the value... but it should show a default as well. the user can backspace and remove the default and key in new value.

But what happens is that when powershell prompts the user the value in the console is blank even though I am assigning a default value in the script (as you can see).

So how can I have a default value in the prompt?

Knows Not Much
  • 30,395
  • 60
  • 197
  • 373
  • Related: [powershell mandatory parameter with default value shown](https://stackoverflow.com/questions/39878202/powershell-mandatory-parameter-with-default-value-shown) – Guy Coder Nov 11 '17 at 16:01

1 Answers1

1

No can do. The best I think you can get is to use a HelpMessage like so:

[Parameter(Mandatory=$true, 
           ParameterSetName='InsertException', 
           HelpMessage='The default value is foo')]

Then when the user encounters the prompt, they type !? to see the help message.

Keith Hill
  • 194,368
  • 42
  • 353
  • 369