Friday, May 30, 2014

Export SharePoint 2007 Search Crawl Log Errors using PowerShell

Requirement: Found so many errors logged in the Search crawl log. Wanted to analyze them.

Solution: Lets use this PowerShell Script to export search crawl errors to CSV:

 #Load SharePoint Assemblies
 [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
 [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.Search")
 
 #Web Application URL
 $url = "http://sharepoint.crescent.com"
 $csID = 4  #Content source id - Local SharePoint sites
      
 #Objects to get Crawl History
 $site = new-Object Microsoft.SharePoint.SPSite($url);
 $context = [Microsoft.Office.Server.Search.Administration.SearchContext]::GetContext($site);
 $logViewer = new-object Microsoft.Office.Server.Search.Administration.logviewer ($context)
   
 $crawlLogFilters = New-Object Microsoft.Office.Server.Search.Administration.CrawlLogFilters
 
 $EndDate = [System.DateTime]::Now
 $StartDate=$endDate.AddDays(-1)
 
 #Content Source Id
 $csProp=[Microsoft.Office.Server.Search.Administration.CrawlLogFilterProperty]::ContentSourceId 
 $crawlLogFilters.AddFilter($csProp, $csID)
 #Get all Errors
 $crawlLogFilters.AddFilter([Microsoft.Office.Server.Search.Administration.MessageType]::Error)  
 #Add Start Date and End Date
 $crawlLogFilters.AddFilter($startDate, $endDate)
 
$startNum = 0
$errorItems += $logViewer.GetCurrentCrawlLogData($crawlLogFilters, ([ref] $startNum))

while($startNum -ne -1)
{
  $crawlLogFilters.AddFilter(“StartAt”, $startNum)
  $startNum = 0; 
  $errorItems += $logViewer.GetCurrentCrawlLogData($crawlLogFilters, ([ref] $startNum))
  #Write-Host "Processing $startNum";
}

$errorItems | Export-CSV "d:\Backup\crawllog.csv" -notypeinformation



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...