0

I'm using the below PowerShell commands to get the last crawl duration. when the Crawl In-progress the 'Crawl Completed' field is empty, I the output as duration in negative values. Could you please help me to get the last crawl duration?

$SPContentSource = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication "Search Service Application" |
Select Name , SuccessCount , CrawlStatus, LevelHighErrorCount, ErrorCount, DeleteCount, WarningCount, CrawlStarted, CrawlCompleted, @{label="CrawlDuration";expression={$_.CrawlCompleted - $_.CrawlStarted}} | ConvertTo-Html -Fragment

enter image description here

0

If the crawl is running and the field is null, you would need to access the crawl log's to retrieve the previous entries instead.

Something like this should work but this is quickly made so you should be able to improve it further.

$ssa = "Search Service Application"

$contentSource = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication $ssa

if(($contentSource.CrawlState -ne 'Idle') -or ($contentSource.CrawlStartTime -eq $null)) {
    [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.Search.Administration.CrawlLog")

    $crawlLog = New-Object Microsoft.Office.Server.Search.Administration.CrawlLog $ssa
    $crawlHistory = $crawlLog.GetCrawlHistory(1, $contentSource.Id)

    $crawlHistory | select ContentSourceName, Successes, TopLevelErrors, Errors, Deletes, Warnings, CrawlStartTime, CrawlEndTime, CrawlDuration | ConvertTo-Html -Fragment

}
else {
    $contentSource | select Name, SuccessCount, CrawlStatus, LevelHighErrorCount, ErrorCount, DeleteCount, WarningCount, CrawlStarted, CrawlCompleted, @{label="CrawlDuration";expression={$_.CrawlCompleted - $_.CrawlStarted}} | ConvertTo-Html -Fragment
}

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.