SharePoint 2013 Search Crawl Log History Report

Requirement: Generate SharePoint 2013 search crawl report daily.

How to Get SharePoint Search Crawl Log?

Crawl history can be viewed from the SharePoint 2013 search service application below, and it gives the crawl log history report for all content sources.

sharepoint 2013 crawl history

Why don’t we automate it with PowerShell to get a crawl history report in Email?

PowerShell to get crawl log history in E-mail:

This PowerShell script extracts crawl history data and sends out emails.

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 the Windows task scheduler to receive Email notifications on a scheduled basis. Here is the script in action:

sharepoint 2013 search crawl history

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

4 thoughts on “SharePoint 2013 Search Crawl Log History Report

  • 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.

    Reply
  • 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?

    Ramsey

    Reply
  • 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?

    Reply

Leave a Reply