title: 'Invoke-Sqlcmd' is not recognized as the name of a cmdlet
body: <p>We have recently started using SQL Server 2012 SP3 and building the SQL server 2012 using a PowerShell script. There is a requirement in our automation process to run multiple database scripts on a db and I have found <code>Invoke-Sqlcmd</code> very reliable until I found this issue.</p>
  <p>When I run <code>Invoke-sqlcmd</code> with a proper set of parameters in PowerShell's debug mode on the system on which the SQL server is installed recently, I don't have problem.</p>
  <blockquote>
  <p>PowershellCommand   : <strong>Invoke-Sqlcmd -InputFile $sStrJBSPExecRolePath -ServerInstance $sStrSQLName -ErrorAction Stop</strong></p>
  </blockquote>
  <p>But when I execute same query through a PowerShell automation script after rebuilding the same server, I end up getting below error </p>
  <blockquote>
  <p>The term 'Invoke-Sqlcmd' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.</p>
  </blockquote>
  <p>I did research online many suggested to Import SQLPS, etc., so for testing I added the below command in my script</p>
  <pre><code>get-pssnapin -Registered
  Import-Module “sqlps” -DisableNameChecking**
  </code></pre>
  <p>Even after adding the above into the script, I still end up with same error. But when I run the same script manually it runs perfectly fine. I don't understand what is wrong.</p>
  <p>PowerShell automation script - This script installs the .Net Framework 3.5, SQL Server 2012, SQL Server 2012 SP3, and then loads the SMO assembly that I use to change SQL settings such as the Max Memory limit of SQL.</p>