50 lines
1.3 KiB
PowerShell
50 lines
1.3 KiB
PowerShell
function Set-ServiceRecoveryAction {
|
|
<#
|
|
.Synopsis
|
|
Set Windows service recovery actions
|
|
.DESCRIPTION
|
|
Set Windows service recovery actions
|
|
Reference:
|
|
https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-R2-and-2012/cc742019(v=ws.11)?redirectedfrom=MSDN
|
|
.EXAMPLE
|
|
Set-ServiceRecoveryAction -Service AppIDSvc
|
|
|
|
#>
|
|
param
|
|
(
|
|
# Service name (not display name)
|
|
[Parameter(Mandatory=$true)]
|
|
[string]
|
|
$Service,
|
|
|
|
# Action delay time in seconds
|
|
[ValidateSet("run", "restart", "reboot")]
|
|
$Action1 = "restart",
|
|
|
|
[int]
|
|
$Time1 = 60,
|
|
|
|
# Action delay time in seconds
|
|
[ValidateSet("run", "restart", "reboot")]
|
|
$Action2 = "restart",
|
|
|
|
[int]
|
|
$Time2 = 60,
|
|
|
|
# Action delay time in seconds
|
|
[ValidateSet("run", "restart", "reboot")]
|
|
$Action3 = "restart",
|
|
|
|
[int]
|
|
$Time3 = 60,
|
|
|
|
|
|
# Specifies the length of the period (in seconds) with no failures after which the failure count should be reset to 0 (zero)
|
|
[int]
|
|
$Reset = 600
|
|
)
|
|
|
|
$actions = '{0}/{1}/{2}/{3}/{4}/{5}' -f $Action1, ($Time1 * 1000), $Action2, ($Time2 * 1000), $Action3, ($Time3 * 1000)
|
|
|
|
sc.exe failure "$service" actions= $actions reset= $Reset
|
|
}
|