Report SharePoint Content Source Last Crawl Duration

Here's a simple Windows PowerShell script example to list out the search service content sources and the last crawl duration times.

 $results = @()

function Get-FormatedTimeSpan()
{
    param([TimeSpan]$TimeSpan)

    if($TimeSpan -and $TimeSpan -eq [TimeSpan]::MinValue -or $TimeSpan -eq [TimeSpan]::MaxValue)
    {
        $TimeSpan = [TimeSpan]::Zero
    }

    return [string]::Format( "{0:D2}:{1:D2}:{2:D2}", $TimeSpan.Days * 24 + $TimeSpan.Hours, $TimeSpan.Minutes, $TimeSpan.Seconds);
}

# enumerate all the search services in the farm
Get-SPEnterpriseSearchServiceApplication | % {

    $searchService = $_
    $crawLog = New-Object Microsoft.Office.Server.Search.Administration.CrawlLog($searchService)

    # enumerate all the content sources for this search service
    $crawLog.GetCrawlStatisticsByContentSource() | % {

        $crawlStats = $_

        $results += New-Object PSObject -Property @{
            "Search Service Application" = $searchService.Name;
            "Content Source Name"        = $crawlStats.ContentSourceName;
            "Last Crawl Duration"        = Get-FormatedTimeSpan -t $crawlStats.LastCrawlDuration
        }
    }
}

$results