Powershell SQLCMD

江枫思渺然 提交于 2019-12-04 15:32:32

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!