PowerShell – Update All SQL Services To Restart On Failure


PowerShell script to quickly change all Recovery Options to “Restart the Service”.

<# Not all "name"s include SQL, such as Integration Services, which are called MsDtsServer110
# Therefore use "displayname" when filtering to capture every SQL service
# All seem to begin with "SQL" #>
$services = Get-Service | Where-Object {$_.displayname -like "*sql*"};
foreach($service in $services){
<# "restart" number is milliseconds —> 60,000 = 1 minute #>
sc.exe failure $service.name reset=0 actions=restart/60000

echo ‘‘;

This site uses Akismet to reduce spam. Learn how your comment data is processed.