title: How to pass parameters to SQL script via Powershell
body: <p>I have a Power-shell script that calls a SQL script. This is currently working, but inside my sql script I have some hard coded parameters that I would like to pass to the SQL script via the powershell. </p>
  
  <p>So this is the snip-it from the Power-shell script</p>
  
  <pre><code>function ExecSqlScript([string] $scriptName)
  {
  $scriptFile = $script:currentDir + $scriptName
  $sqlLog = $script:logFileDir + $scriptName + "_{0:yyyyMMdd_HHmmss}.log" -f (Get-Date)
  $result = sqlcmd -S uk-ldn-dt270 -U sa -P passwordhere3! -i $scriptFile -b | Tee-Object -             filepath $sqlLog
  
   if ($result -like "*Msg *, Level *, State *" -Or $result -like "*Sqlcmd: Error:*") 
      {
      throw "SQL script " + $scriptFile + " failed: " + $result
      }   
  }
  
  try
  {
      ExecSqlScript "restoreDatabase.sql"
  }
  catch
  {
   //Some Error handling here
  }
  </code></pre>
  
  <p>And this is from the SQL</p>
  
  <pre><code>USE MASTER
  GO
  DECLARE @dbName varchar(255)
  SET @dbName = 'HardCodedDatabaseName'
  </code></pre>
  
  <p>So I want to pass the value for dbName, any ideas?</p>