functions/Set-WindowsServiceRecovery.ps1

<#
.SYNOPSIS
Sets the recovery state for services to retry after a specific time
.DESCRIPTION
Sets the recovery state for services to retry after a specific time
 
Copyright (C) 2017 UKHO
 
.EXAMPLE
Set-WindowsServiceRecovery -ServerName $env:ComputerName -ServiceName "W3SVC" -RestartTimeout 180000
 
.PARAMETER ServerName
Parameter description
 
.PARAMETER ServiceName
Parameter description
 
.PARAMETER RestartTimeout
Timeout in milliseconds, default is 180000 (3 minutes)
 
.NOTES
RestartTimeout is in miliseconds, 180000 milliseconds is round 3 minutes.
#>

function Set-WindowsServiceRecovery
{
    [CmdletBinding()]
    param(
        [string]
        [Parameter(Mandatory=$true)]
        $ServerName,
        [string] 
        [Parameter(Mandatory=$true)]
        $ServiceName,
        [int]
        $RestartTimeout = 180000)    
    begin {
    }
    process {
        &sc.exe "\\$ServerName" failure "$ServiceName" reset= 0 actions= restart/$RestartTimeout
    }
    end {
    }
}