问题
We were experiencing problems with Powershell and SQLCMD, when there was sapces in the -v parameter variable powershell wouldn't run the command.
e.g.
sqlcmd ... -v VAR="Some space"
Has anyone experienced this before or know how to fix the problem?
Thanks,
B
回答1:
The syntax above works for the PS commandline but fails within a script.
We struggled a long time with how to make this work. One of our very clever QA guys finally came up with the following:
$variableWithSpaces="one two three"
$mySqlCmd = "sqlcmd -E -S $dbServer -i $script -v var=```"$variableWithSpaces```" "
Invoke-Expression $mySqlCmd
Plug ugly but it works.
回答2:
Powershell will actually pass the parameter to the program as "VAR=Some space"
. Maybe sqlcmd stumbles over this. By using
VAR=`"Some space`"
instead it will get passed as VAR="Some space"
. Maybe that resolves the problem.
来源:https://stackoverflow.com/questions/1015038/powershell-sqlcmd