function Set-ServiceRecoveryOneRestart { <# .SYNOPSIS Set the service with specified name to restart once, then no more recovery actions .PARAMETER ServiceName The service name to set the state for #> [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions","",Justification="Alkami does not typically check for should-proceed for intentionally state changing operations")] [CmdletBinding()] param ( [string]$ServiceName ) $logLead = (Get-logLeadName) if ($null -eq (Get-Service -Name $ServiceName)) { Write-Warning "$logLead : [$ServiceName] does not appear to be a valid service. Can not set the service recovery restart" return } <# from the sc.exe failure configuration options message: DESCRIPTION: Changes the actions upon failure USAGE: sc failure [service name] ... OPTIONS: reset= (Must be used in conjunction with actions= ) reboot= command= actions= > (Must be used in conjunction with the reset= option) #> # action/time//// # This sets the first one to be restart after 10s, then nothing else $recoveryActions = "restart/10000////" # 86400 = default (24 hours) Write-Host "$logLead : Setting recovery actions for [$ServiceName]" Invoke-SCExe @("failure",$ServiceName,"actions=",$recoveryActions,"reset=",86400) if ($LASTEXITCODE -ne 0) { Write-Error "$logLead : Attempt to call sc.exe and set failure recovery actions errored out. Please review logs" } else { Write-Host "$logLead : Recovery options set successfully for [$ServiceName]" } Write-Host "$logLead : Setting failureflag to 1" Invoke-SCExe @("failureflag",$ServiceName,"1") if ($LASTEXITCODE -ne 0) { Write-Error ("$logLead : An error occurred setting the failure flag option for service $ServiceName") } }