July 27, 2017 at 6:14 am
Hi all
I'm new to Powershell and Google didn't turn up anything useful (or that I could get working) so I'm here asking for help.
I've got a script that requires parameters but I'd like a slightly better prompt than the one I'm getting.
This is my parameters:-
[Parameter(Mandatory=$True] [string]$servername, # this is server to upload to
This gives me a prompt of:
servername:
What I'd like to do is have a prompt of :-
Enter a server name:
but I'm not sure how to go about it.
I don't want to use Read-Host as I want to be able to call this from the command line.
I've tried:-
[Parameter(Mandatory=$True,HelpMessage="Enter a server name")] [string]$servername, # this is server to upload to
but it doesn't change the prompt.
Can I do what I want and, if so, where am I going wrong?
August 1, 2017 at 9:18 am
Remove the Mandatory=$True
Then check if servername was entered on the command line. If not use read-host to get it with your custom prompt.if (! $servername) { $servername = read-host "Enter a server name...?" }
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply