PowerShell Script: Get-SPHealthScore

The Get-SPHealthScore power shell commandlet is a simple commandlet that will query the value of the health score for any SharePoint 2010 URL (providing the header hasn’t been removed for security reasons which I will discuss in a later post).

function Get-SPHealthScore([string]$url)
{
    $request = [System.Net.WebRequest]::Create($url)
    $request.Method = "HEAD"
    $response = $request.GetResponse()
    if(($score = $response.Headers.Get("X-SharePointHealthScore")) -ne$null)
    {
        Write-Host $score
    }
    else
    {
        Write-Host 'The specified URL is not a SharePoint 2010 site or does not contain a health score'
    }
}

If you’re not familiar with the health score header, it is added to any SharePoint response for use by Microsoft Office applications in order for them to reduce their request rate if the server is particularly busy. The score ranges from 0 – 10 although the server would unlikely respond with anything higher than an 8 as the higher the value, the busier the server up until the request is throttled.