title: Syntax error when run in as step in SQL Server Agent Job
body: <p>Below scripts works perfectly fine, when you run it in PowerShell window.</p>
  
  <pre><code>Import-Csv $DestinationFile | ForEach-Object {
      Invoke-Sqlcmd -Database $database -ServerInstance $server -Query "INSERT INTO $table VALUES ('$($SourceFile)','$($_.LineNumber)','$($_.LineDescription)','$($_.Criteria)','$($_.LineValue)')"
  }
  </code></pre>
  
  <p>But when you run this script through SQL Server Agent job ... it gives syntax error.</p>
  
  <p>Also below mentioned line doesn't work when scheduled as a job.</p>
  
  <pre><code>$objWord = New-Object -Com Word.Application
  $objWord.Visible = $false # $false
  </code></pre>
  
  <p>Using PowerShell, we search the docs and based on pattern search, results we found... we import them into the database.</p>
  
  <p>All working good when you run in PowerShell console, but when you try to run PS1 file through SQL Server it doesn't do anything.</p>