Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell HelpMessage displayed by default in parameters

Is it possible to have PowerShell display the help messages by default when parameters are not specified in the command line without the user having to input "!?" for help?

Should I not use param and do it manualy instead with Read-Host if I want my script to be interactive?

param (  
    [Parameter(Mandatory=$true,HelpMessage="Enter desired password.")][string]$desired_password,
    [Parameter(Mandatory=$true,HelpMessage="Please input target hostnames.")][string[]]$target_hosts
)

What would be the best approach in such case?

like image 477
trox Avatar asked Oct 16 '25 16:10

trox


1 Answers

Unfortunately, currently it's not possible to make a friendly prompt for a missing parameter without Read-Host. But this could be done in a more elegant manner than in Bill's answer:

param(
  [String] $TestParameter=$(Read-Host -prompt "Enter the test parameter")
)
like image 146
montonero Avatar answered Oct 18 '25 09:10

montonero