Skip to content

Instantly share code, notes, and snippets.

@nordineb
Last active June 4, 2018 07:36
Show Gist options
  • Save nordineb/5f4f47879c7adb42cafb6b77533a32c1 to your computer and use it in GitHub Desktop.
Save nordineb/5f4f47879c7adb42cafb6b77533a32c1 to your computer and use it in GitHub Desktop.
Set Windows services to delayed-auto with restart on failure

Given a list of windows services

  • Start each of them
  • Configure each of them to start automatically, but with a delay
  • On failure, restart the service
$services = ("OctopusDeploy Tentacle","seq","tcagent","mailhog","freeFTPdService")
foreach ($service in $services){
  Start-Service  -Name $Service
  sc.exe config  $Service start= "delayed-auto"
  sc.exe failure $service reset= 86400 actions= restart/5000/restart/5000/reboot/5000
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment