functions/Get-WindowsServiceRecovery.ps1

<#
.SYNOPSIS
Gets the recovery state for services to retry after a specific time
.DESCRIPTION
Gets the recovery state for services to retry after a specific time
 
Copyright (C) 2017 UKHO
.LINK
 
.EXAMPLE
Get-WindowsServiceRecovery -ServerName $env:ComputerName -ServiceName "W3SVC"
 
RestartTimeout is in miliseconds, 180000 miliseconds is round 3 minutes.
#>

function Get-WindowsServiceRecovery
{
    [CmdletBinding()]
    [OutputType([System.Collections.Hashtable])]
    param(
        [string]
        [Parameter(Mandatory=$true)]
        $ServerName,
        [string] 
        [Parameter(Mandatory=$true)]
        $ServiceName
        )
    begin {
        $return = @{}
    }
    process {
        $script = sc.exe "\\$ServerName" qfailure W3SVC

        for($i = 0;$i -lt $script.Length;$i++)
        {
            $arr = $script[$i] -split ':'
            if($arr.Count -eq 2)
            {
                $return."$($arr[0].Trim())" = "$($arr[1].Trim())"
            }
        }

    }
    end {
        $return
    }
}