title: Powershell's Invoke-Command not working when called from Windows Task Scheduler
body: <p>I have a Powershell script, which is working just fine, when called from command line, but only partially fine when executed by the Windows Task Scheduler. The script looks as follows:</p>
  
  <pre><code># Do things, which are always working.
  $session = new-pssession -computername SRV
  Invoke-Command -session $session -scriptblock { D:\script.bat }
  # Do things, which are always working.
  </code></pre>
  
  <p>The task defined in the Task Scheduler is completed without errors. As you see, all parts before and after <code>Invoke-Command</code> are working, also when called by the Task Scheduler. Only the <code>Invoke-Command</code> itself is only working when called from the command line.</p>
  
  <p>My only guess is, that the Powershell script is exiting prematurely, but I didn't find any way to confirm this or even solve the issue.</p>