Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

We have a setup where SharePoint 2010 crawls several file share locations. After the crawls, we have ended up with thousands of errors. What I want to do is to export all these errors preferably to Excel instead of having to page through hundreds of pages on Central Admin.

I specifically want to export error messages for a particular content source. Is there an easy way to achieve this with PowerShell?

Edit:

I used a PowerShell script that exports all error messages as follows, but I can't figure out how to export only error messages pertaining to just one Content Source amongst all the different content sources in my Search Application:

$ssa = Get-SPEnterpriseSearchServiceApplication | Where-Object 
{$_.Name -eq "Search Service Application"}

$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

share|improve this question
add comment

2 Answers 2

The script below is based on Microsoft blog team which sets an example on how to export the Crawl Logs

#============================================================================ 
#Powershell script to pull all the crawl logs and display based on errorId 
#============================================================================ [IO.Directory]::SetCurrentDirectory((Convert-Path (Get-Location -PSProvider FileSystem)))
#Replace "Search Service Application" in the script with the exact name of the SSA that you browse to for viewing the crawl log. 
#With FAST you have multiple Search SSA’s and hence specify the name of the SSA that you use to view the crawl log data. 
$ssa = Get-SPEnterpriseSearchServiceApplication | Where-Object {$_.Name -eq "UoN FAST Search Connector Service Application"} 
#This should list only one SSA object. 
$ssa 
#Create a LogViewer object associated with that SSA 
$logViewer = New-Object Microsoft.Office.Server.Search.Administration.Logviewer $ssa 
#Get a List of all errors/warnings in the Crawl Log
$ErrorList = $logViewer.GetAllStatusMessages() | Select ErrorId 
#Loop through each type of error and pull that data $currentUser = [Environment]::UserDomainName + "\" + [Environment]::UserName;
$machine = [Environment]::MachineName;
$date = ( get-date ).ToString('yyyyMMdd');
$logFile = "$date-installationlog.txt";
if ($logfile -eq $null)
{
  $logFile = New-Item -type file "$date-installationlog.txt"; 
}
Foreach ($errorId in $ErrorList) 
{ 
    $crawlLogFilters = New-Object Microsoft.Office.Server.Search.Administration.CrawlLogFilters 
    #Filter based on the Error Id 
    $crawlLogFilters.AddFilter("MessageId", $errorId.errorId)        
    "Pulling data for Message ID : " + $errorId.errorId 
    $nextStart = 0 
    $urls = $logViewer.GetCurrentCrawlLogData($crawlLogFilters, ([ref] $nextStart)) 
    #Data from the crawl log will be available in the DataTable $urls. If this number is larger than the number of records requested (50 by default), then use only 50 records, ignore the rest. 
    WHILE($nextStart -ne -1)
 {
  $crawlLogFilters.AddFilter("StartAt", $nextStart);
  $nextStart = 0;
  $urls = $logViewer.GetCurrentCrawlLogData($crawlLogFilters, ([ref] $nextStart));

  for ($i=0; $i -le $urls.Rows.Count -1 ; $i++)
  {
   # Just output the URL, the Error (if any) and the Error Code.
   [System.String]::Format('{0},{1}, {2}',$urls.Rows[$i].DisplayUrl, $urls.Rows[$i].ErrorMsg, $urls.Rows[$i].ErrorLevel) | Out-File $logFile -append;
  } 
 } 
}

If you're looking for specific content amongst the crawl logs, not just errors, you can just export to a text file and then use Notepad++ http://notepad-plus-plus.org/ as a search tool which has a fantastic search capability.

share|improve this answer
    
Looks like Microsoft.Office.Server.Search.Administration.Logviewer class is obsolete in the newer version, anybody knows what is equivalent to this class now? –  Sudhir Kesharwani Oct 31 '13 at 19:56
add comment

Give this a try (uncomment the lines that you want to use)

    $ssa = Get-SPEnterpriseSearchServiceApplication | Where-Object {$_.Name -eq "Search Service Application"}
$ssaContent = new-object Microsoft.Office.Server.Search.Administration.Content($ssa)

$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 -or $errorId.errorId -eq 2 -or $errorId.errorId -eq 745)
    {

    }
    else
    {
        $crawlLogFilters = New-Object Microsoft.Office.Server.Search.Administration.CrawlLogFilters;
        $crawlLogFilters.AddFilter("MessageId", $errorId.errorId);
        #$crawlLogFilters.AddFilter("Url", "Contains", "\\officeshare\user");
        #$crawlLogFilters.AddFilter("ContentSourceId", 86);
        "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
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.