Reviewing Search History using PowerShell and Out-GridView

Have you ever wanted to be able to review the history of your search service application in a way where you could export it to excel, or easily filter it based on criteria that you specify?

 

This handy-dandy script, that I did not write, will let you do just that!  All you need to do is save it into a .ps1 file and then execute it.  The result will be a kick-butt grid view that allows you to sort and filter based on your criteria.  Very useful in Troubleshooting SharePoint.

 

$numberOfResults = 1000
$contentSourceName = "Local SharePoint Sites"
 
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.Search.Administration")
 
$searchServiceApplication = Get-SPEnterpriseSearchServiceApplication
$contentSources = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication $searchServiceApplication
$contentSource = $contentSources | ? { $_.Name -eq $contentSourceName }
 
$crawlLog = new-object Microsoft.Office.Server.Search.Administration.CrawlLog($searchServiceApplication)
$crawlHistory = $crawlLog.GetCrawlHistory($numberOfResults, $contentSource.Id)
$crawlHistory.Columns.Add("CrawlTypeName", [String]::Empty.GetType()) | Out-Null
 
# Label the crawl type
$labeledCrawlHistory = $crawlHistory | % {
$_.CrawlTypeName = [Microsoft.Office.Server.Search.Administration.CrawlType]::Parse([Microsoft.Office.Server.Search.Administration.CrawlType], $_.CrawlType).ToString()
return $_
}
 
$labeledCrawlHistory | Out-GridView

Find this and much, much more in my newest book, TroubleShooting SharePoint, available on Amazon!