1

I would like to find out if it is possible to receive a notification via email or be able to check a status somewhere when an incremental crawl gets stuck running for a duration of time. We typically find out about this the hard way from the end users report search results are not returning new content. The only way I know to check this is to do it manually by going into central admin and looking at the search crawl log to see if the incremental crawls are all under “x” amount of time. I wish I could be notified if the incremental craw exceeded “x” amount of time so my team can investigate the cause. Does anyone know of any way of accomplishing this?

For example, our incremental searches run for a few minutes at a time, if incremental search job ever exceeds an hour we would like to know.

2

There's no direct way to do this, but here's what you could do.

$ssa = Get-SPEnterpriseSearchServiceApplication
$cs = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication $ssa -Identity 'Local SharePoint Sites'
$dt = Get-Date
#value in minutes
if($dt.Subtract($cs.CrawlStarted).TotalMinutes -gt '60')  {
    Send-MailMessage [...]
}
  • you never fetched the crawls from the Get-SPEnterpriseSearchCrawlContentSource – Heiko Hatzfeld_MSFT Apr 3 '18 at 22:12
0

I don't think that SharePoint is providing such feature (if incremental search job ever exceeds an hour we would like to know via email).

But apart from that, you will get an email if the error comes while crawling content source using below PowerShell: (Reference)

** I believe, in your case, Trevor Seward approach will work.

#Powershell Script which to Send a daily Alert Mail when an error occurs during Search Crawl.
#This solution is for SharePoint Server 2013 (on-Premises)
# Author: Ram Prasad Meenavalli

#----------------------------------------------------
#Parameters Required
#----------------------------------------------------
$ssaName = "Search Service Application"
$errorsFileName = "errors.csv"
$topErrorsFileName = "toplevelerrors.csv"

#$logMaxRows - This specifies the number of errors to be sent in the mail attachment. 
$logMaxRows = 10000

#$contentSourceID - This specifies the Content Source ID where we need to check for Crawl Errors.
#-1 will give crawl errors from all content sources.
$contentSourceID = -1



#----------------------------------------------------
# Email Variables
#----------------------------------------------------
$smtp = "smtp-server-address" 
$to = "ram@yourmail.com","prasad@yourmail.com"
$from = "no-reply@yourmail.com"
$subject = "Search Crawl Errors"
$body = "Your Search Service has encountered some errors while crawling the content. Please check the attachment/s for more details."

#----------------------------------------------------
# Constants
#----------------------------------------------------
$errorID = -1
$currentDate = Get-Date
$startDate = $currentDate.AddDays(-1)
$endDate = (($startDate.AddHours(23)).AddMinutes(59)).AddSeconds(59)


if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)
{
    Add-PSSnapin Microsoft.SharePoint.PowerShell
}

$ssa = Get-SPEnterpriseSearchServiceApplication -Identity $ssaName
$logs = New-Object Microsoft.Office.Server.Search.Administration.CrawlLog $ssa

$errors = $logs.GetCrawledUrls($true,$logMaxRows,"",$false,$contentSourceID,2,$errorID,$startDate,$endDate)
$topErrors = $logs.GetCrawledUrls($true,$logMaxRows,"",$false,$contentSourceID,4,$errorID,$startDate,$endDate)

if(($errors.Rows[0]["DocumentCount"] -gt 0) -or ($topErrors.Rows[0]["DocumentCount"] -gt 0))
{
    $logs.GetCrawledUrls($false,$logMaxRows,"",$false,$contentSourceID,2,$errorID,$startDate,$endDate) | export-csv -notype $errorsFileName
    $logs.GetCrawledUrls($false,$logMaxRows,"",$false,$contentSourceID,4,$errorID,$startDate,$endDate) | export-csv -notype $topErrorsFileName  

    send-MailMessage -SmtpServer $smtp -To $to -From $from -Subject $subject -Body $body -BodyAsHtml -Attachments $errorsFileName,$topErrorsFileName
}

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.