Skip to content
Tech Shizz Logo

An Engineers Blog

  • TechShizz
  • blog

How to set Service recovery options via PowerShell

Posted on February 23, 2021 By rich No Comments on How to set Service recovery options via PowerShell

Run this function, then run the new Cmd-let that it creates. Replace the server name with the one you want to set the settings for. Replace the Service name with the Display name of the service you want to set.

  1. function Set-ServiceRecovery{
  2. [alias(‘Set-Recovery’)]
  3. param
  4. (
  5. [string] [Parameter(Mandatory=$true)] $ServiceDisplayName,
  6. [string] [Parameter(Mandatory=$true)] $Server,
  7. [string] $action1 = “restart”,
  8. [int] $time1 = 30000, # in miliseconds
  9. [string] $action2 = “restart”,
  10. [int] $time2 = 30000, # in miliseconds
  11. [string] $actionLast = “restart”,
  12. [int] $timeLast = 30000, # in miliseconds
  13. [int] $resetCounter = 4000 # in seconds
  14. )
  15. $serverPath = “\” + $server
  16. $services = Get-CimInstance -ClassName ‘Win32_Service’ -ComputerName $Server| Where-Object {$_.DisplayName -imatch $ServiceDisplayName}
  17. $action = $action1+“/”+$time1+“/”+$action2+“/”+$time2+“/”+$actionLast+“/”+$timeLast
  18. foreach ($service in $services){
  19. # https://technet.microsoft.com/en-us/library/cc742019.aspx
  20. $output = sc.exe $serverPath failure $($service.Name) actions= $action reset= $resetCounter
  21. }
  22. }
  23. Set-ServiceRecovery -ServiceDisplayName “My Service” -Server “PHOSTA”

Post navigation

❮ Previous Post: How to RDP to an AzureAD Joined Client PC
Next Post: Disable Copy and Paste and Right Mouse Click ❯

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

Subscribe to our newsletter!

Recent Posts

  • How to implement a lightning-fast ransomware playbook
  • How to achieve defence in depth in your business
  • How to implement a SecOps team phishing response plan
  • How to block an Office 365 Sign-in correctly
  • Microsoft finally patched serious Exchange 0-day over a month old!

Recent Comments

    Archives

    • November 2022
    • July 2021
    • March 2021
    • February 2021

    Categories

    • Cyber Security
    • Uncategorized

    Meta

    • Log in
    • Entries feed
    • Comments feed
    • WordPress.org

    Copyright © 2023 .

    Theme: Oceanly News Dark by ScriptsTown