PowerShell Service – How to Configure Auto-Restart After Failure

powershellservicewindows

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

Recovery Options when managing a Windows Service

How can I configure this with PowerShell?

Best Answer

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