title: Invoke-Sqlcmd, InputFile, and Variable
body: <p>I need to exec a powershell script that exec a SQL script to create a database.
  Based on my knowledge I exec the powershell command in this way:</p>
  
  <p><strong>Init.ps1</strong></p>
  
  <pre><code>$DATABASEFILENAME = "C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL2008INSTANCE\MSSQL\DATA\myDB.mdf"
  $DATABASELOGNAME = "C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL2008INSTANCE\MSSQL\DATA\myDB_log.ldf"
  $DBUSEROWNER = "domain\spsetup"
  </code></pre>
  
  <p><strong>CreateDatabase.ps1</strong></p>
  
  <pre><code> try {
          $createDatabaseScript = ($scriptsFolder,$eachRelease,$DeployEnvironment,"Config" -join "\") + "\JM SiteRequest Database.sql"
          $sqlVariable = "DATABASEFILENAME = '$DATABASEFILENAME'", "DATABASELOGNAME = '$DATABASELOGNAME'", "DBUSEROWNER = '$DBUSEROWNER'"
  
          Invoke-Sqlcmd -ServerInstance "$MySQLServer" -InputFile "$createDatabaseScript" -ErrorAction Stop -Variable $sqlVariable
  }
  catch [Exception] {
          Write-Error "Database error: $_.Exception"
  }
  </code></pre>
  
  <p><strong>SQL script</strong></p>
  
  <pre><code>CREATE DATABASE [SiteRequestDB] ON  PRIMARY
  ( NAME = N'SiteRequestDB', FILENAME = N'$(DATABASEFILENAME)' , SIZE = 3072KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB ) LOG ON 
  ( NAME = N'SiteRequestDB_log', FILENAME = N'$(DATABASELOGNAME)' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
  GO
  </code></pre>
  
  <p>I updated the $sqlVariable as @Chad Miller suggested.
  So the problem was there.
  Now I got this error: <em>Creating the database error: Database error: An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Change the alias to a valid name.
  The label 'C' has already been declared. Label names must be unique within a query batch or stored procedure..Exception.Exception</em></p>