0

On my service recovery tab on service failure I selected to run a Program. In the Program to run I entered C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe and in the arguments I entered -command "& {C:\Scripts\PS\recover.ps1}". The script when executed manually works as expected, but when I'm stopping the service or terminating it using Task Manager the script is not executed?

Yuri
  • 2,820
  • 4
  • 28
  • 40
  • Why are you executing a command which executes a scriptblock which calls a file instead of just using the `-File` parameter of `powershell.exe`? – briantist Aug 03 '16 at 20:02
  • Try replacing the powershell script with a simple echo to file or similar to verify that powershell.exe is executing. It could be a permissions issue around scripts. – Guvante Aug 03 '16 at 20:02
  • @Guvante account is admin on the box – Yuri Aug 03 '16 at 20:16
  • @braintist I believe -File belongs to V2 I'm using v1 – Yuri Aug 03 '16 at 20:24
  • get-executionpolicy returns Unrestricted – Yuri Aug 03 '16 at 20:32
  • 1
    @Yuri v1 is extremely rare, are you sure you're using v1? Which OS? Note that the `v1.0` in the file path is a misnomer; that's the path for every version of powershell. [Check your version](http://stackoverflow.com/q/1825585/3905079) with `$PSversionTable`. – briantist Aug 03 '16 at 20:35
  • Sorry, @braintist - you right I have v4, but from PS my file works as expected using -command PS C:\> c:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command C:\scripts\ps\email.ps1 , From service recovery does not – Yuri Aug 03 '16 at 20:54
  • Definitely try -File as the previous posters have suggested. It works on my systems. – Glen Buktenica Aug 04 '16 at 03:27

1 Answers1

0

The script in recovery tab does not fire if service stopped normally. As soon as I terminated the service using task manager/kill command from command prompt - it works. Thank you everybody

Yuri
  • 2,820
  • 4
  • 28
  • 40