title: Passing path scripting variable to sqlcmd when called using Invoke-Expression
body: <p>I'm trying to create a powershell script that creates a database. The relevant part of the createDb.ps1 is:</p>
  
  <pre><code>param([string] $server,
        [string] $dbName)
  $scriptpath = "C:\script\path" 
  $cDb = "master"
  $line = "script.sql"
  $outfile = "\log.txt"
  $dbDir = "C:\database path\"
  $command = @"
  sqlcmd -b -S $server -d $cDb -i '$scriptpath\$line' -o '.$outfile' -v dbLocation='$dbDir' dbName=$dbName
  "@
  
  Invoke-Expression $command
  </code></pre>
  
  <p>I call the script with the following parameters:</p>
  
  <pre><code>createDb.ps1 -server localhost -dbName TestDb
  </code></pre>
  
  <p>However when I run this I get the following error: </p>
  
  <pre><code>sqlcmd: 'dbDir=C:\database path\" dbName=TestDb': Invalid argument. Enter '-?' for help.
  </code></pre>
  
  <p>When I execute the following from the command line, everything works as expected:</p>
  
  <pre><code>sqlcmd -b -S localhost -d master -i "C:\script\path\script.sql" -o ".\log.txt" -v dbLocation="C:\database path\" dbName=TestDb
  </code></pre>