<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Imagine Think Create Share : Powershell</title><link>http://blogs.msdn.com/carloshm/archive/tags/Powershell/default.aspx</link><description>Tags: Powershell</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>How to: Programmatically read the ChangeLog in PowerShell </title><link>http://blogs.msdn.com/carloshm/archive/2009/06/05/how-to-programmatically-read-the-changelog-in-powershell.aspx</link><pubDate>Fri, 05 Jun 2009 15:33:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9701271</guid><dc:creator>carloshm</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/carloshm/comments/9701271.aspx</comments><wfw:commentRss>http://blogs.msdn.com/carloshm/commentrss.aspx?PostID=9701271</wfw:commentRss><description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;When I was working to get &lt;A title="How to: Programmatically Export the Crawl History to a CSV File in PowerShell" href="http://blogs.msdn.com/carloshm/archive/2009/03/31/how-to-programmatically-export-the-crawl-history-to-a-csv-file-in-powershell.aspx" mce_href="http://blogs.msdn.com/carloshm/archive/2009/03/31/how-to-programmatically-export-the-crawl-history-to-a-csv-file-in-powershell.aspx"&gt;powershell&lt;/A&gt; &lt;A title="How to: Programmatically Manage the Crawl of a Content Source in PowerShell " href="http://blogs.msdn.com/controlpanel/blogs/how-to-programmatically-manage-the-crawl-of-a-content-source-in-powershell" mce_href="http://blogs.msdn.com/controlpanel/blogs/how-to-programmatically-manage-the-crawl-of-a-content-source-in-powershell"&gt;scripts&lt;/A&gt; from MSDN samples to get/set information, I created&amp;nbsp;too one for reading the changelog. It was a bit tricky to build, but I manage to port &lt;A title="Querying for Specific Changes" href="http://msdn.microsoft.com/en-us/library/bb447550.aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb447550.aspx"&gt;Querying for specific changes&lt;/A&gt; to PowerShell.&lt;/P&gt;
&lt;P&gt;You can review the changelog&amp;nbsp;API in the Microsoft SharePoint Developer Documentation Team Blog and MSDN (previous link):&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/sharepointdeveloperdocs/archive/2008/01/21/synchronizing-with-windows-sharepoint-services-part-1.aspx"&gt;http://blogs.msdn.com/sharepointdeveloperdocs/archive/2008/01/21/synchronizing-with-windows-sharepoint-services-part-1.aspx&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/sharepointdeveloperdocs/archive/2008/01/22/synchronizing-with-windows-sharepoint-services-part-2.aspx"&gt;http://blogs.msdn.com/sharepointdeveloperdocs/archive/2008/01/22/synchronizing-with-windows-sharepoint-services-part-2.aspx&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;We wanted to monitor which changes were been read by the crawl process and been able to filter specific changes.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;## 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") &lt;BR&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;function global:Get-ChangeLog($url, $minutes, $changetype)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;trap [Exception] {&lt;BR&gt;&amp;nbsp;&amp;nbsp;write-error $("ERROR: " + $_.Exception.GetType().FullName); &lt;BR&gt;&amp;nbsp;&amp;nbsp;write-error $("ERROR: " + $_.Exception.Message); &lt;BR&gt;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;continue;&amp;nbsp; &amp;nbsp;&lt;BR&gt;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;$s = new-Object Microsoft.SharePoint.SPSite($url);&lt;BR&gt;&amp;nbsp;$startTime = [System.DateTime]::Now.Subtract([System.TimeSpan]::FromMinutes($minutes));&lt;BR&gt;&amp;nbsp;&lt;BR&gt;&amp;nbsp;$db_id = [Microsoft.SharePoint.Administration.SPContentDatabase].getmethod("get_Id");&lt;BR&gt;&amp;nbsp;$result_id = $db_id.Invoke($s.ContentDatabase, "instance,public", $null, $null, $null);&lt;BR&gt;&amp;nbsp;&lt;BR&gt;&amp;nbsp;$db_CurrentChangeToken = [Microsoft.SharePoint.Administration.SPContentDatabase].getmethod("get_CurrentChangeToken");&lt;BR&gt;&amp;nbsp;$result_CurrentChangeToken = $db_CurrentChangeToken.Invoke($s.ContentDatabase, "instance,public", $null, $null, $null);&lt;BR&gt;&amp;nbsp;&lt;BR&gt;&amp;nbsp;$startToken = New-Object Microsoft.SharePoint.SPChangeToken([Microsoft.SharePoint.SPChangeCollection+CollectionScope]::ContentDB, $result_id.ToString(), $startTime);&lt;BR&gt;&amp;nbsp;&lt;BR&gt;&amp;nbsp;$changeQuery = New-Object Microsoft.SharePoint.SPChangeQuery($False, $False);&lt;BR&gt;&amp;nbsp;$changeQuery.User = $True;&lt;BR&gt;&amp;nbsp;$changeQuery.ContentType = $True;&lt;BR&gt;&amp;nbsp;$changeQuery.Add = $True;&lt;BR&gt;&amp;nbsp;$changeQuery.Delete = $True;&lt;BR&gt;&amp;nbsp;$changeQuery.Field = $True;&lt;BR&gt;&amp;nbsp;$changeQuery.File = $True;&lt;BR&gt;&amp;nbsp;$changeQuery.Folder = $True;&lt;BR&gt;&amp;nbsp;$changeQuery.Group = $True;&lt;BR&gt;&amp;nbsp;$changeQuery.GroupMembershipAdd = $True;&lt;BR&gt;&amp;nbsp;$changeQuery.GroupMembershipDelete = $True;&lt;BR&gt;&amp;nbsp;$changeQuery.Item = $True;&lt;BR&gt;&amp;nbsp;$changeQuery.List = $True;&lt;BR&gt;&amp;nbsp;$changeQuery.Move = $True;&lt;BR&gt;&amp;nbsp;$changeQuery.Rename = $True;&lt;BR&gt;&amp;nbsp;$changeQuery.Site = $True;&lt;BR&gt;&amp;nbsp;$changeQuery.SystemUpdate = $True;&lt;BR&gt;&amp;nbsp;$changeQuery.Update = $True;&lt;BR&gt;&amp;nbsp;&lt;BR&gt;&amp;nbsp;$changeQuery.ChangeTokenStart = $startToken;&lt;BR&gt;&amp;nbsp;$changeQuery.ChangeTokenEnd = $result_CurrentChangeToken;&lt;BR&gt;&amp;nbsp;&lt;BR&gt;&amp;nbsp;$db_GetChanges = [Microsoft.SharePoint.Administration.SPContentDatabase].getmethod("GetChanges", [Microsoft.SharePoint.SPChangeQuery]);&lt;BR&gt;&amp;nbsp;$result_GetChanges = $db_GetChanges.Invoke($s.ContentDatabase, "instance,public", $null, $changeQuery, $null);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;write-Output $result_GetChanges | Where-Object { $_.ChangeType -eq $changetype };&lt;/P&gt;
&lt;P&gt;&amp;nbsp;$s.Dispose();&lt;BR&gt;}&lt;/P&gt;
&lt;P&gt;Get-ChangeLog -url &lt;A href="http://your_site_url/"&gt;http://your_site_url&lt;/A&gt; -minutes 120 -changetype Add&lt;BR&gt;&lt;/P&gt;
&lt;P&gt;Take into account that the time will get changes based on UTC&lt;/P&gt;
&lt;P&gt;Bye!&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9701271" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/carloshm/archive/tags/SharePoint/default.aspx">SharePoint</category><category domain="http://blogs.msdn.com/carloshm/archive/tags/Codeplex/default.aspx">Codeplex</category><category domain="http://blogs.msdn.com/carloshm/archive/tags/Search/default.aspx">Search</category><category domain="http://blogs.msdn.com/carloshm/archive/tags/MOSS/default.aspx">MOSS</category><category domain="http://blogs.msdn.com/carloshm/archive/tags/Powershell/default.aspx">Powershell</category></item><item><title>How to: Programmatically Manage the Crawl of a Content Source in PowerShell </title><link>http://blogs.msdn.com/carloshm/archive/2009/03/31/how-to-programmatically-manage-the-crawl-of-a-content-source-in-powershell.aspx</link><pubDate>Tue, 31 Mar 2009 19:53:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9523361</guid><dc:creator>carloshm</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/carloshm/comments/9523361.aspx</comments><wfw:commentRss>http://blogs.msdn.com/carloshm/commentrss.aspx?PostID=9523361</wfw:commentRss><description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;If you have read my &lt;A title="How to: Programmatically Export the Crawl History to a CSV File in PowerShell " href="http://blogs.msdn.com/carloshm/archive/2009/03/31/how-to-programmatically-export-the-crawl-history-to-a-csv-file-in-powershell.aspx" mce_href="http://blogs.msdn.com/carloshm/archive/2009/03/31/how-to-programmatically-export-the-crawl-history-to-a-csv-file-in-powershell.aspx"&gt;previous post&lt;/A&gt; you may think, why did you stop there? Well, that is what I thought too&amp;nbsp;:), and started with &lt;A title="How to: Programmatically Manage the Crawl of a Content Source" href="http://msdn.microsoft.com/en-us/library/aa679491.aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa679491.aspx"&gt;this article&lt;/A&gt; from MSDN.&lt;/P&gt;
&lt;P&gt;We wanted to start managing the crawling of our content source more programmatically, as we have seen that running several at the same time affects the overall process.&lt;/P&gt;
&lt;P&gt;So running these powershell scripts as scheduled task and monitoring the status can improve in crawling.&lt;/P&gt;
&lt;P&gt;You may improve them reusing the context and content sources and&amp;nbsp;doing some &lt;EM&gt;pipeline&lt;/EM&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;to be included in the overall file:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;## SharePoint Reference&lt;BR&gt;[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") &lt;BR&gt;[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Administration") &lt;BR&gt;[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.Search.Administration") &lt;BR&gt;[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.Search") &lt;BR&gt;[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server") &lt;BR&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;STRONG&gt;To start an incremental crawl of the content source&lt;/STRONG&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;function global:StartIncremental-Crawl($url, $csname)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;trap [Exception] {&lt;BR&gt;&amp;nbsp;&amp;nbsp;write-error $("ERROR: " + $_.Exception.GetType().FullName); &lt;BR&gt;&amp;nbsp;&amp;nbsp;write-error $("ERROR: " + $_.Exception.Message); &lt;BR&gt;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;continue;&amp;nbsp; &amp;nbsp;&lt;BR&gt;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;$s = new-Object Microsoft.SharePoint.SPSite($url);&lt;BR&gt;&amp;nbsp;$c = [Microsoft.Office.Server.Search.Administration.SearchContext]::GetContext($s);&lt;BR&gt;&amp;nbsp;$sc = new-Object Microsoft.Office.Server.Search.Administration.Content($c);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;$cs = $sc.ContentSources[$csname];&lt;/P&gt;
&lt;P&gt;&amp;nbsp;$cs.StartIncrementalCrawl();&lt;/P&gt;
&lt;P&gt;&amp;nbsp;$s.Dispose();&lt;BR&gt;}&lt;/P&gt;
&lt;P&gt;StartIncremental-Crawl -url &lt;A href="http://your_site_url/"&gt;http://your_site_url&lt;/A&gt; -csname "your content source name"&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;STRONG&gt;To start a full crawl of the content source&lt;/STRONG&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;function global:StartFull-Crawl($url, $csname)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;trap [Exception] {&lt;BR&gt;&amp;nbsp;&amp;nbsp;write-error $("ERROR: " + $_.Exception.GetType().FullName); &lt;BR&gt;&amp;nbsp;&amp;nbsp;write-error $("ERROR: " + $_.Exception.Message); &lt;BR&gt;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;continue;&amp;nbsp; &amp;nbsp;&lt;BR&gt;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;$s = new-Object Microsoft.SharePoint.SPSite($url);&lt;BR&gt;&amp;nbsp;$c = [Microsoft.Office.Server.Search.Administration.SearchContext]::GetContext($s);&lt;BR&gt;&amp;nbsp;$sc = new-Object Microsoft.Office.Server.Search.Administration.Content($c);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;$cs = $sc.ContentSources[$csname];&lt;/P&gt;
&lt;P&gt;&amp;nbsp;$cs.StartFullCrawl();&lt;/P&gt;
&lt;P&gt;&amp;nbsp;$s.Dispose();&lt;BR&gt;}&lt;/P&gt;
&lt;P&gt;StartFull-Crawl -url &lt;A href="http://your_site_url/"&gt;http://your_site_url&lt;/A&gt; -csname "your content source name"&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;STRONG&gt;To pause a crawl in process&lt;/STRONG&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;function global:Pause-Crawl($url, $csname)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;trap [Exception] {&lt;BR&gt;&amp;nbsp;&amp;nbsp;write-error $("ERROR: " + $_.Exception.GetType().FullName); &lt;BR&gt;&amp;nbsp;&amp;nbsp;write-error $("ERROR: " + $_.Exception.Message); &lt;BR&gt;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;continue;&amp;nbsp; &amp;nbsp;&lt;BR&gt;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;$s = new-Object Microsoft.SharePoint.SPSite($url);&lt;BR&gt;&amp;nbsp;$c = [Microsoft.Office.Server.Search.Administration.SearchContext]::GetContext($s);&lt;BR&gt;&amp;nbsp;$sc = new-Object Microsoft.Office.Server.Search.Administration.Content($c);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;$cs = $sc.ContentSources[$csname];&lt;/P&gt;
&lt;P&gt;&amp;nbsp;$cs.PauseCrawl();&lt;/P&gt;
&lt;P&gt;&amp;nbsp;$s.Dispose();&lt;BR&gt;}&lt;/P&gt;
&lt;P&gt;Pause-Crawl -url &lt;A href="http://your_site_url/"&gt;http://your_site_url&lt;/A&gt; -csname "your content source name"&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;STRONG&gt;To resume a paused crawl&lt;/STRONG&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;function global:Resume-Crawl($url, $csname)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;trap [Exception] {&lt;BR&gt;&amp;nbsp;&amp;nbsp;write-error $("ERROR: " + $_.Exception.GetType().FullName); &lt;BR&gt;&amp;nbsp;&amp;nbsp;write-error $("ERROR: " + $_.Exception.Message); &lt;BR&gt;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;continue;&amp;nbsp; &amp;nbsp;&lt;BR&gt;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;$s = new-Object Microsoft.SharePoint.SPSite($url);&lt;BR&gt;&amp;nbsp;$c = [Microsoft.Office.Server.Search.Administration.SearchContext]::GetContext($s);&lt;BR&gt;&amp;nbsp;$sc = new-Object Microsoft.Office.Server.Search.Administration.Content($c);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;$cs = $sc.ContentSources[$csname];&lt;/P&gt;
&lt;P&gt;&amp;nbsp;$cs.ResumeCrawl();&lt;/P&gt;
&lt;P&gt;&amp;nbsp;$s.Dispose();&lt;BR&gt;}&lt;/P&gt;
&lt;P&gt;Resume-Crawl -url &lt;A href="http://your_site_url/"&gt;http://your_site_url&lt;/A&gt; -csname "your content source name"&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;STRONG&gt;To stop a crawl of the content source&lt;/STRONG&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;function global:Stop-Crawl($url, $csname)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;trap [Exception] {&lt;BR&gt;&amp;nbsp;&amp;nbsp;write-error $("ERROR: " + $_.Exception.GetType().FullName); &lt;BR&gt;&amp;nbsp;&amp;nbsp;write-error $("ERROR: " + $_.Exception.Message); &lt;BR&gt;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;continue;&amp;nbsp; &amp;nbsp;&lt;BR&gt;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;$s = new-Object Microsoft.SharePoint.SPSite($url);&lt;BR&gt;&amp;nbsp;$c = [Microsoft.Office.Server.Search.Administration.SearchContext]::GetContext($s);&lt;BR&gt;&amp;nbsp;$sc = new-Object Microsoft.Office.Server.Search.Administration.Content($c);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;$cs = $sc.ContentSources[$csname];&lt;/P&gt;
&lt;P&gt;&amp;nbsp;$cs.StopCrawl();&lt;/P&gt;
&lt;P&gt;&amp;nbsp;$s.Dispose();&lt;BR&gt;}&lt;/P&gt;
&lt;P&gt;Stop-Crawl -url &lt;A href="http://your_site_url/"&gt;http://your_site_url&lt;/A&gt; -csname "your content source name"&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;STRONG&gt;To check the crawl status values for a content source&lt;/STRONG&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;function global:Get-CrawlStatus($url)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;trap [Exception] {&lt;BR&gt;&amp;nbsp;&amp;nbsp;write-error $("ERROR: " + $_.Exception.GetType().FullName); &lt;BR&gt;&amp;nbsp;&amp;nbsp;write-error $("ERROR: " + $_.Exception.Message); &lt;BR&gt;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;continue;&amp;nbsp; &amp;nbsp;&lt;BR&gt;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;$s = new-Object Microsoft.SharePoint.SPSite($url);&lt;BR&gt;&amp;nbsp;$c = [Microsoft.Office.Server.Search.Administration.SearchContext]::GetContext($s);&lt;BR&gt;&amp;nbsp;$sc = new-Object Microsoft.Office.Server.Search.Administration.Content($c);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Write-Output $sc.ContentSources;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;$s.Dispose();&lt;BR&gt;}&lt;/P&gt;
&lt;P&gt;Get-CrawlStatus -url &lt;A href="http://your_site_url/"&gt;http://your_site_url&lt;/A&gt; | Format-Table -property CrawlStatus, CrawlStarted, CrawlCompleted&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Enjoy!&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9523361" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/carloshm/archive/tags/SharePoint/default.aspx">SharePoint</category><category domain="http://blogs.msdn.com/carloshm/archive/tags/Codeplex/default.aspx">Codeplex</category><category domain="http://blogs.msdn.com/carloshm/archive/tags/Search/default.aspx">Search</category><category domain="http://blogs.msdn.com/carloshm/archive/tags/MOSS/default.aspx">MOSS</category><category domain="http://blogs.msdn.com/carloshm/archive/tags/HowTo/default.aspx">HowTo</category><category domain="http://blogs.msdn.com/carloshm/archive/tags/Powershell/default.aspx">Powershell</category></item><item><title>How to: Programmatically Export the Crawl History to a CSV File in PowerShell</title><link>http://blogs.msdn.com/carloshm/archive/2009/03/31/how-to-programmatically-export-the-crawl-history-to-a-csv-file-in-powershell.aspx</link><pubDate>Tue, 31 Mar 2009 18:51:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9523116</guid><dc:creator>carloshm</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/carloshm/comments/9523116.aspx</comments><wfw:commentRss>http://blogs.msdn.com/carloshm/commentrss.aspx?PostID=9523116</wfw:commentRss><description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;When I came across the article at MSDN &lt;A title="Crawl History to a CSV" href="http://msdn.microsoft.com/en-us/library/cc789570.aspx" mce_href="http://msdn.microsoft.com/en-us/library/cc789570.aspx"&gt;How to: Programmatically Export the Crawl History to a CSV File&lt;/A&gt;&amp;nbsp;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.&lt;/P&gt;
&lt;P&gt;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 ;)&lt;A title=comment01_carloshm name=comment01_carloshm&gt;&lt;/A&gt;), 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)&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;## SharePoint Reference&lt;BR&gt;[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") &lt;BR&gt;[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Administration") &lt;BR&gt;[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.Search.Administration") &lt;BR&gt;[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.Search") &lt;BR&gt;[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server") &lt;BR&gt;&lt;/P&gt;
&lt;P&gt;function global:Get-CrawlHistory($url)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;trap [Exception] {&lt;BR&gt;&amp;nbsp;&amp;nbsp;write-error $("ERROR: " + $_.Exception.GetType().FullName); &lt;BR&gt;&amp;nbsp;&amp;nbsp;write-error $("ERROR: " + $_.Exception.Message); &lt;BR&gt;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;continue;&amp;nbsp; &amp;nbsp;&lt;BR&gt;&amp;nbsp;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;$s = new-Object Microsoft.SharePoint.SPSite($url);&lt;BR&gt;&amp;nbsp;$c = [Microsoft.Office.Server.Search.Administration.SearchContext]::GetContext($s);&lt;BR&gt;&amp;nbsp;$h = new-Object Microsoft.Office.Server.Search.Administration.CrawlHistory($c);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Write-OutPut $h.GetCrawlHistory();&lt;/P&gt;
&lt;P&gt;&amp;nbsp;$s.Dispose();&lt;BR&gt;}&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then you can just execute: Get-CrawlHistory -url &lt;A href="http://your_site_url/"&gt;http://your_site_url/&lt;/A&gt; | &lt;A title=Export-Csv href="https://www.microsoft.com/technet/scriptcenter/topics/msh/cmdlets/export-csv.mspx" mce_href="https://www.microsoft.com/technet/scriptcenter/topics/msh/cmdlets/export-csv.mspx"&gt;Export-Csv&lt;/A&gt; your_path_and_file_name&lt;/P&gt;
&lt;P&gt;Then you can import to excel and make some charts.&lt;/P&gt;
&lt;P&gt;In order to filter the information some useful columns should be denormalized: CrawlType, ContentSourceID, Status.&lt;/P&gt;
&lt;P&gt;Cheers!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9523116" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/carloshm/archive/tags/SharePoint/default.aspx">SharePoint</category><category domain="http://blogs.msdn.com/carloshm/archive/tags/Codeplex/default.aspx">Codeplex</category><category domain="http://blogs.msdn.com/carloshm/archive/tags/Search/default.aspx">Search</category><category domain="http://blogs.msdn.com/carloshm/archive/tags/MOSS/default.aspx">MOSS</category><category domain="http://blogs.msdn.com/carloshm/archive/tags/HowTo/default.aspx">HowTo</category><category domain="http://blogs.msdn.com/carloshm/archive/tags/Powershell/default.aspx">Powershell</category></item></channel></rss>