Monday, January 6, 2014

Start SharePoint Search Crawl using PowerShell

For some reasons, SharePoint search crawl scheduled didn't trigger. So I used this PowerShell script and Windows Task scheduler to trigger Incremental crawls.

Start SharePoint Search Full/Incremental Crawl using PowerShell:

Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

#Get the search service application
$SSA = Get-SPEnterpriseSearchServiceApplication -Identity "Search Service Application" 

#Get the Local SharePoint sites content source
$ContentSource = $SSA | Get-SPEnterpriseSearchCrawlContentSource -Identity "Local SharePoint sites"

  #Check if Crawler is not already running
  if($ContentSource.CrawlState -eq "Idle")
        {
            Write-Host "Starting Incremental Crawl..."            
            $ContentSource.StartIncrementalCrawl()
            #$ContentSource.StartFullCrawl();
            #$ContentSource.PauseCrawl()
            #$ContentSource.StopCrawl()
       }
  else
  {
   Write-Host "Another Crawl is already running!"
   Write-Host "NAME: ", $ContentSource.Name, " - ", $ContentSource.CrawlStatus
  }   
We can also start / stop Search crawls in SharePoint 2013 or in SharePoint 2010 using this single line of PowerShell script:
Get-SPEnterpriseSearchCrawlContentSource -SearchApplication "Search Service Application" | where-object { ($_.Name -eq "Local SharePoint Sites") -and ($_.CrawlStatus -eq "idle") } | foreach { $_.StartIncrementalCrawl() }

Start Incremental Crawl in MOSS 2007 using PowerShell:

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

$ServerContext = [Microsoft.Office.Server.ServerContext]::Default
$context =  [Microsoft.Office.Server.Search.Administration.SearchContext]::GetContext($ServerContext) 

$SSPContent = new-object Microsoft.Office.Server.Search.Administration.Content($context) 
$SSPContentSources =  $SSPContent.ContentSources 

foreach ($ContentSource in $SSPContentSources) 
{ 
  if ($ContentSource.Name -eq "Local Office SharePoint Server sites")
  {
    Write-Host "NAME: ", $ContentSource.Name, " - ", $ContentSource.CrawlStatus
    if ($ContentSource.CrawlStatus -eq [Microsoft.Office.Server.Search.Administration.CrawlStatus]::Idle)
    {
     Write-Host "Starting Incremental crawl"
       $ContentSource.StartIncrementalCrawl();
    }
    else
    {
       Write-Host "Another Crawl is already running!"
    }
  }
} 
This was helpful when user came with an requirement to run incremental crawl for each 15 min!



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

1 comment :

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...