Thursday, February 27, 2014

Resume SharePoint Crawls with PowerShell

Recently I worked on PowerShell script which is used to resume paused crawls.

We notice newly implemented backup solution is pausing the SharePoint ongoing crawls and over completion of the backup crawls not getting resume as expected.

This caused issue of delayed crawls and need manual intervention to resume paused crawls. Solution was to file post script over completion of the backup.

SharePoint Environment 2007

Script input : Site url and Content sources


########################### Load SharePoint assembles ############################

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.Search")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Sharepoint")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")

#####################################################################

$sspURL= "Put your site name here"
$ContentSources = @("content1","content2")
$site = new-object Microsoft.SharePoint.SPSite($sspURL)
$CrawlStatus =""

# get spsite from $Url
$searchContext = [Microsoft.Office.Server.Search.Administration.SearchContext]::GetContext($site)

#Dispose site object
$Site.Dispose()

# get searchContext from spsite
$content = new-object Microsoft.Office.Server.Search.Administration.Content($searchContext)
$ContentSourceCollection = $content.ContentSources
foreach($item in $ContentSources)
{
    $oContentSource = $ContentSourceCollection[$item]
    if($oContentSource )
    {
       if($oContentSource.CrawlStatus -eq  "Paused" )
       {
          $oContentSource.ResumeCrawl()
          $CrawlStatus= $CrawlStatus+ $oContentSource.Name +" was paused Now "+ $oContentSource.CrawlStatus+" | "
       }
   }
}
Write-Host  $CrawlStatus

No comments:

Post a Comment