title: PowerShell script run using Windows Task Scheduler is not running a SQL Server SSIS DTEXEC.EXE job
body: <p>Hopefully this question is unique enough not to be a duplicate.  I have a PowerShell script which does two things.</p>
  
  <ol>
  <li>Inserts records into a SQL Server table </li>
  <li>Writes text to a text file</li>
  </ol>
  
  <p>For the purpose of this post, I have simplified the script.  On my computer, the script is located at C:\Temp\ssis.ps1.  Following is the contents of the script.</p>
  
  <pre><code>DTEXEC.EXE /F "C:\Temp\ssisjob.dtsx"    
  $date = Get-Date
  Write-Output "This PowerShell script file was last run on $date" &gt;&gt; C:\Temp\test.txt  
  </code></pre>
  
  <p>When I manually run this PowerShell script, records are inserted into the SQL Server table, and a line of text is written to the test.txt file.  If I schedule this script to run using Windows Task Scheduler, a new line of text is written to the text file, but the records are not inserted into the SQL Server table. This tells me that Windows Task Scheduler is able to run the PowerShell script. However, for some unknown reason, Windows Task Scheduler seems to not want to run the SSIS job (DTEXEC.EXE) part of the script.  Event Viewer confirms there is an issue with the SSIS job.  I am running Microsoft SQL Server 2014, Developer Version.</p>
  
  <p><a href="https://i.stack.imgur.com/GZc85.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GZc85.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/sVORu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sVORu.png" alt="enter image description here"></a></p>
  
  <p>In my task, on the Actions tab, the Add arguments field has the following reference: C:\Temp\ssis.ps1.  Task Scheduler is configured to run with the highest privileges.</p>
  
  <p><a href="https://i.stack.imgur.com/HyDy2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HyDy2.png" alt="enter image description here"></a></p>
  
  <p>I have tried all of the following Execution Policies in PowerShell.  Regardless of the Execution Policy I select, my experience does not change.</p>
  
  <ul>
  <li>Bypass</li>
  <li>Unrestricted</li>
  <li>RemoteSigned</li>
  </ul>
  
  <p>The History tab in Task Scheduler has <em>information</em> events, but no <em>error</em> events.  </p>
  
  <p><a href="https://i.stack.imgur.com/Q8Gve.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Q8Gve.png" alt="enter image description here"></a></p>
  
  <p>I do not have the permission to view the SQL Server logs (this is a production server).</p>
  
  <p>I have been debugging this issue for a few weeks, and I have read numerous posts here on Stack Overflow, yet I still cannot seem to find the answer, so hopefully I have done my due diligence before making a new post here.  I could add some additional observations, but I do not want my post here to get extensively long.  If anyone has any hints or tips or insight that might lead me down the right path, it would be greatly appreciated.</p>