Ho to configure a service auto-restart after failure with PowerShell

by Luke   Last Updated September 11, 2019 14:00 PM

On a Windows system, in the Service console, there is a recovery tab to configure actions for a service in case of failure.

enter image description here

How can I configure this with PowerShell?

Answers 1

There is currently no native PowerShell cmdlet to manage the service recovery.
However, to auto-restart a service when it fails you can use SC.
(In a PowerShell prompt you must precede it with & and use the full name sc.exe)

& sc.exe failure msftpsvc reset= 30 actions= restart/5000

The official documentation is on Microsoft Docs under Sc Failure

September 11, 2019 13:50 PM

Related Questions

Powershell - check if string is in list of strings

Updated November 03, 2017 13:00 PM