title: Running a Powershell Script on Windows Service Failure. Works when run manually but not when service fails. Advice needed
body: <p>So I have been working on a script to essentially send an email when a Service fails. The script works just fine, as I've run it manually from PowerShell. I get the email and everything checks out.
  I then add this to the service:
  <a href="https://i.stack.imgur.com/CYHbM.png" rel="nofollow noreferrer">Service Recovery Options</a></p>
  
  <p>I tell it to run Powershell by linking to the executable:</p>
  
  <pre><code>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
  </code></pre>
  
  <p>And the execute the following script:</p>
  
  <pre><code>-command C:\Users\andreand\Desktop\Sendmail.ps1
  </code></pre>
  
  <p>As mentioned, I tried this manually in PowerShell, and I got an error. If I append the PowerShell location before the -command it works. Like so:</p>
  
  <pre><code>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command C:\Users\andreand\Desktop\Sendmail.ps1
  </code></pre>
  
  <p>So this works if I run it manually, but when the service fails, nothing happens.
  I trigger a failure by doing <code>/taskkill /F /PID pid</code>, and I can see the service has stopped.</p>
  
  <p>What am I missing? I feel like I am so close and it is frustrating!</p>