title: Scripting SSIS Packages to run remotely with PowerShell
body: <p>I am trying to run some SSIS Packages installed on a database remotely, I do have access to the database and can see the SSISDB and its Catalog.  The problem I have been having is how best to execute one of the packages in the Project I have in the catalog.</p>
  
  <p>I know DTExec is an option if I use invoke-command but don't want to do that if it's possible, at times there may be multiple connections and I have seen crashes on certain boxes with multiple executions of DTExec.</p>
  
  <p>I have tried getting the execute script from the package and putting that in PowerShell and using that as a SQL Query, my long term fear with this method is if the Packages change then I need to keep track of that.</p>
  
  <p>The simplest solution I would like to have is execute the package just by name, if I need to update the name that's simpler than an entire SQL script for each package.  Is this simpler solution possible and what would be the best method to do it?  So far I have had no luck running this as an execute with SMO.  What I have tried is something like:</p>
  
  <pre><code>[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | out-null
  $SMOserver = New-Object ('Microsoft.SqlServer.Management.Smo.Server') -argumentlist $Server
  
  #This sets the connection to mixed-mode authentication
  $SMOserver.ConnectionContext.LoginSecure=$true
  
  $query = @" this is where my execute SQL goes from the SSIS catalog "@
  
  $db2 = New-Object ('Microsoft.SqlServer.Management.Smo.Database')
  $db2 = $SMOserver.Databases[$database]
  Write-Host "My Query: $query"
  $results2 = $db2.ExecuteNonQuery($query)
  Write-Host "Results: " $results2
  </code></pre>
  
  <p>Although when I run this I often just get a return, with no values.</p>