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
finally worked it out. for the next sucker to try this here is the solution
powershell script looks like
$myPath = "`"C:\Path`""
sqlcmd.exe -SmySQLInstance -i./test.sql -v myvar=$myPath
my test.sql file can then use the variable like this
PRINT "$(myvar)"
the key here is understanding how powershell does escape characters. More info on that here