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?
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")
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With