The SharePoint search logs can be powerful, highlighting issues either in the search configuration or content. These are displayed within the browser, but sometimes you need to run deeper analysis on the SharePoint search crawl logs.
There is no built-in way (that I know of) to export the crawl log, but PowerShell can help us.
Below is a simple script to do this. The script will obtain all of the error codes, itterate them, gather the logs for the error code & then finally export everything to a csv file.
Note that this script excludes error codes 0 & 1 ( success and deletes) as I only wanted to look at errors.
# Change the name of the Search Service to that in use on the server
$ssa = Get-SPEnterpriseSearchServiceApplication | Where-Object {$_.Name -eq "Search Service"}
$logViewer = New-Object Microsoft.Office.Server.Search.Administration.Logviewer $ssa
$ErrorList = $logViewer.GetAllStatusMessages() | Select ErrorId
Foreach ($errorId in $ErrorList)
{
If ($errorId.errorId -eq 0 -or $errorId.errorId -eq 1)
{
}
else
{
$crawlLogFilters = New-Object Microsoft.Office.Server.Search.Administration.CrawlLogFilters
$crawlLogFilters.AddFilter(“MessageId”, $errorId.errorId)
"Processing Error Code : " + $errorId.errorId
$startNum = 0
$errorItems += $logViewer.GetCurrentCrawlLogData($crawlLogFilters, ([ref] $startNum))
Write-Host "Processing $startNum"
WHILE($startNum -ne -1){$crawlLogFilters.AddFilter(“StartAt”, $startNum);$startNum = 0;$errorItems += $logViewer.GetCurrentCrawlLogData($crawlLogFilters, ([ref] $startNum));Write-Host "Processing $startNum";
}
}
}
$errorItems | Export-CSV crawllog.csv