1

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
0
$sources = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication "Search Service Application DEV"
ForEach ($source in $sources) {
    if ($source.CrawlStatus -ne "Idle") {
        $time1 = ((Get-Date) - $source.CrawlStarted)
        $time1 =  Get-Date "$time1" -Format HH:mm:ss
        if($time1.Hours -ge 3 )
        {
            Write-Host $source.Name $time1
        }
    }
}
  • Please don't add the exact same answer to this question, as you did on this one. Instead, try to specify your answer further to make it a better of this specific question. Thank You! – Benny Skogberg Sep 7 '17 at 6:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.