Is there a way to get the last crawl duration of all the content sources in SharePoint 2010 using power shell?
i tried below script but it gave me an error.
$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