You can do 1 of 2 things.
Mark the parameter as required, then powershell will automatically ask the user:
PARAM( [Parameter(Mandatory=$true)][string]$sql ) PROCESS { "You entered: " + $sql }
which gives:
or you can provide the expression as a default parameter, requesting input from the user:
PARAM( [string]$sql = (read-host "Enter a value for sql parameter") ) PROCESS { "You entered: " + $sql }
which gives:
Edit:
In response to your comment. The only workarounds that I can think of to get the desired behavior are either to not specify the parameters, but to process the $ args argument myself. Or you can use a hack that pushes the task to parse the arguments into a separate function, and then delays any errors that may occur when this function is called. So your script will look like this:
function parsePrompt ( [string]$sql) { $sql } $cmd = "parsePrompt $($args -join " ")" try { $sql = invoke-expression $cmd } catch [System.Management.Automation.ParameterBindingException] { $sql = read-host "Enter a value for sql parameter" } "You entered: " + $sql
which gives:
source share