I am trying to pass in some scripting variables to Invoke-Sqlcmd in PowerShell like so:
$hello = "hello"
$params = "greeting=" + $hello, "audience=world"
Invoke-Sqlcmd -Query "select '`$(greeting) `$(audience)'" -Variable $params
I get the following error:
The format used to define the new variable for Invoke-Sqlcmd cmdlet is invalid. Please use the 'var=value' format for defining a new variable.
But I am successful if I remove $hello
and use a literal:
$params = "greeting=hello", "audience=world"
.GetType()
returns the same thing for both versions of $params
, so I'm unsure what the issue is.