passing path to SqlCmd within powershell script

后端 未结 4 2107
面向向阳花
面向向阳花 2021-02-13 09:28

I\'m trying to write a powershell script which will execute sqlcmd.exe to run a sql script. The script contains a SQLCMD variable which I want to pass in on the command line via

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-13 10:14

    Had the same issue, found the solution accidentally, still don't understand why it works :) (i'm not a powershell pro though):

    sqlcmd -d ... -s ... -v Var1Name=("""$PowershellVar1""") Var2Name=("""$PowershellVar2""")
    

    Variables $PowershellVar1 and $PowershellVar2 have string type in my PS script and can contain quotes, spaces etc

提交回复
热议问题