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.
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)
Figured it out myself. Because Powershell works with .net objects rather than text, you need to use get-content to expose the contents of the text files. So to perform what I was trying to do in the question, use:
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
)The official documentation is on Microsoft Docs under Sc Failure