How to: Programmatically Export the Crawl History to a CSV File in PowerShell
Hi,
When I came across the article at MSDN How to: Programmatically Export the Crawl History to a CSV File I thought I would never create such a tool just for that specific feature, as you end up with additional requirements in order to create an admin tool.
But today I needed to get data from crawl history, and I didn't want to get them from SQL (remember it is not supported ;)), so I started to write down a simple powershell script to do it. And then I realized that for this atomic actions, indeed it is a great options!: you give admin people multiple commands that they can use/combine to monitor/get information about the environment (and yes many, many things more)
## SharePoint Reference
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Administration")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.Search.Administration")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.Search")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")function global:Get-CrawlHistory($url)
{
trap [Exception] {
write-error $("ERROR: " + $_.Exception.GetType().FullName);
write-error $("ERROR: " + $_.Exception.Message);
continue;
}$s = new-Object Microsoft.SharePoint.SPSite($url);
$c = [Microsoft.Office.Server.Search.Administration.SearchContext]::GetContext($s);
$h = new-Object Microsoft.Office.Server.Search.Administration.CrawlHistory($c);Write-OutPut $h.GetCrawlHistory();
$s.Dispose();
}
Then you can just execute: Get-CrawlHistory -url https://your_site_url/ | Export-Csv your_path_and_file_name
Then you can import to excel and make some charts.
In order to filter the information some useful columns should be denormalized: CrawlType, ContentSourceID, Status.
Cheers!
Comments
- Anonymous
March 31, 2009
PingBack from http://www.anith.com/?p=24938 - Anonymous
March 31, 2009
Hi, If you have read my previous post you may think, why did you stop there? Well, that is what I thought - Anonymous
June 05, 2009
Hi, When I was working to get powershell scripts from MSDN samples to get/set information, I created - Anonymous
August 12, 2010
what are minimal MOSS rights required for executing this code? - Anonymous
November 15, 2010
Hi There,Thanks for the sample. FYI, I tried but the CSV file is 0KB. Not sure what I miss or the requiremnt not met. Can you advice? - Anonymous
February 25, 2011
This code only works for Sharepoint 2007. Has anyone been able to get crawl logs for Sharepoint 2010? - Anonymous
July 22, 2014
Yes it also works for SharePoint 2010, Brent - Anonymous
November 10, 2014
Has anyone been able to get crawl logs for SharePoint 2013 ? - Anonymous
October 30, 2015
PowerShell script to generate Crawl history report on SharePoint 2013: www.sharepointdiary.com/.../sharepoint-2013-search-crawl-log-history-report.html