title: passing path to SqlCmd within powershell script
body: <p>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 sqlcmd's -v switch. The problem is that powershell is doing something weird when I pass a path as the value of one of my variables which in turn causes the SQL script to fail.</p>
  
  <p>For example I'm calling:</p>
  
  <pre><code>$path = 'C:\path'
  sqlcmd -SMySQLServerInstance  -i 'MySqlScript.sql'  -v MyVariablePath=$path
  </code></pre>
  
  <p>when run I receive a error which says:</p>
  
  <pre><code>Sqlcmd: ':\path': Invalid argument.
  </code></pre>
  
  <p>No amount of double or single quotes that I have tried around <code>$path</code> or <code>MyVariablePath=$path</code>
  solves the issue.</p>
  
  <p>Can somebody provide a simple canonical example of how this needs to be done?</p>