I needed this today but I also needed the delay times.
Based on the linked answer I was able to extend boxdog's answer and add them as well:
function Get-ServiceRecovery {
Param($ServiceName)
$failureActions = (Get-ItemProperty hklm:\system\currentcontrolset\services\$ServiceName).FailureActions
$possibleActions = 'NoAction', 'RestartService','RestartComputer','RunProgram'
[PsCustomObject]@{
Service = $ServiceName
FirstFailure = $possibleActions[$failureActions[20]]
FirstDelayMs = Get-Delay -ByteArray $failureActions[24..27]
SecondFailure = $possibleActions[$failureActions[28]]
SecondDelayMs = Get-Delay -ByteArray $failureActions[32..35]
SubsequentFailure = $possibleActions[$failureActions[36]]
SubsequentDelayMs = Get-Delay -ByteArray $failureActions[40..43]
ResetDelayS = Get-Delay -ByteArray $failureActions[0..3]
}
}
function Get-Delay {
Param($ByteArray)
$binary = "";
for ($i=$ByteArray.Length-1; $i -ge 0; $i--) {
$binary += Convert-To8BitBinary -byte $ByteArray[$i]
}
return Convert-ToDecimal -binary $binary
}
function Convert-To8BitBinary {
Param($byte)
return ([string][convert]::ToString($byte, 2)).PadLeft(8, '0')
}
function Convert-ToDecimal {
Param($binary)
return ([string][convert]::ToInt32($binary, 2))
}
Get-ServiceRecovery -ServiceName $serviceName
Now, calling like this: Get-ServiceRecovery -ServiceName 'W32Time'
gives output like this:
Service : W32Time
FirstFailure : RestartService
FirstDelayMs : 60000
SecondFailure : RestartService
SecondDelayMs : 120000
SubsequentFailure : NoAction
SubsequentDelayMs : 0
ResetDelayS : 86400