I am looking for a way to get a PowerShell script to request a parameter that should be required, but shown with a default value, for example:
.\psscript
Supply values for the following parameters:
parameter1[default value]:
parameter2[1234]:
I want to request input, but provide some default values.
If I use the required parameter, it requests the values, but does not show the default value or processes the given value. Unless I make it mandatory, PowerShell does not query the value at all.
Here are some sample scripts I tried:
[CmdletBinding()]
Param(
[parameter(Mandatory=$true)] $SqlServiceAccount = $env:computername + "_sa",
[parameter(Mandatory=$true)] $SqlServiceAccountPwd
)
This script requests parameters, but does not show or does not process the default value if I just press the enter key on the first parameter.
[CmdletBinding()]
Param(
[parameter(Mandatory=$false)] $SqlServiceAccount = $env:computername + "_sa",
[parameter(Mandatory=$true)] $SqlServiceAccountPwd
)
This script does not request the first parameter, but processes the default value.