SharePoint 2013 Search Crawl Log History Report

Requirement: Generate SharePoint 2013 search crawl report on daily basis.

Solution: Crawl history can be viewed from SharePoint 2013 search service application as in the below screen. It gives the crawl log history report for all content sources.
sharepoint 2013 crawl history
Why don't we automate it with PowerShell, so that we'll get crawl history report in E-mail?

PowerShell to get crawl log history in E-mail:
This PowerShell script extracts crawl history data and sends out Email.
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

#Get the search service application
$SSA = Get-SPEnterpriseSearchServiceApplication #-Identity "Search Service Application Name"

#Get all content sources
$ContentSources = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication $SSA #| where {$_.Name -eq $ContentSourceName}

$ReportDate = Get-Date -format "dd-MM-yyyy"

#CSS Styles for the Table
$style = "Crawl History Report: "
$style = $style + "<style>BODY{font-family: Arial; font-size: 10pt;}"
$style = $style + "TABLE{border: 1px solid black; }"
$style = $style + "TH{border: 1px solid black; background: #dddddd; padding: 5px; }"
$style = $style + "TD{border: 1px solid black; padding: 2px; }"
$style = $style + "</style>"

#Frame Email body
$EmailBody = $ContentSources | Select Name, SuccessCount, WarningCount, ErrorCount,CrawlStarted,CrawlCompleted,  @{label="CrawlDuration";expression={$_.CrawlCompleted - $_.CrawlStarted}} | ConvertTo-Html -Head $style 

#Set Email configurations

#Get outgoing Email Server
$EmailServer = (Get-SPWebApplication -IncludeCentralAdministration | Where { $_.IsAdministrationWebApplication } ) | %{$_.outboundmailserviceinstance.server} | Select Address

$From = "[email protected]"
$To = "[email protected]"
$Subject = "Crawl History Report as on: "+$ReportDate
$Body = "Hi SharePoint Team,<br /><br />Here is a Crawl History report as on $ReportDate <br /><br />" + $EmailBody

#Send Email
Send-MailMessage -smtpserver $EmailServer.Address -from $from -to $to -subject $subject -body $body -BodyAsHtml
Schedule the above script in Windows task scheduler to receive E-mail notifications on schedule basis. Here is the script in action:
sharepoint 2013 search crawl history


  1. It is a great script. Thanks for sharing. Only thing I would like to do is filter it on full crawls only. Is that possible?

  2. Hi there, this works but it only emails the recent crawl history. I want to see all history for the same day. How can I modify it?


  3. It's worked well.. thank you. But, when running the script, if crawl in progress, and the "crawlcompleted" field is empty, then i am getting the crawl duration in negative values. Could you please help how to resolve this? Instead of negative values, we can set the duration like in progress or showing empty.


Please Login and comment to get your questions answered!

Powered by Blogger.