Tuesday, 29 May 2012

Force stop and then start a full crawl on all content sources in a SharePoint 2010 farm using PowerShell

There have been many times where I have needed to run a full crawl of all content sources on a SharePoint 2010 farm, but I quite often there are already crawls taking place, which I prefer to stop before starting a new one.

The script below walks through each content source and does the following:

  1. Checks whether the crawl status is set to “Idle”
  2. If the content source is currently involved in a crawl activity, stop the activity and wait until the status changes back to Idle
  3. If the content source is Idle, then start a full crawl

To use, run the following script in the SharePoint Management Shell, replacing “Search Service Application” with the name of your Search service application:

Get-SPEnterpriseSearchCrawlContentSource -SearchApplication "Search Service Application" | ForEach-Object {
    if ($_.CrawlStatus -ne "Idle")
    {
        Write-Host "Stopping currently running crawl for content source $($_.Name)..."
        $_.StopCrawl()
       
        do { Start-Sleep -Seconds 1 }
        while ($_.CrawlStatus -ne "Idle")
    }
   
    Write-Host "Starting full crawl for content source $($_.Name)..."
    $_.StartFullCrawl()
}

For info, you can use the following script if you want to display the crawl status of all content sources on your farm:

Get-SPEnterpriseSearchCrawlContentSource -SearchApplication "Search Service Application" | select Name, CrawlStatus

This will give you an output similar to the following:

image

30 comments:

  1. Is there a way to force stop a crawl and keep it from resuming on schedule without modifying the schedule itself?

    ReplyDelete
    Replies
    1. You could stop the crawl and then pause the content source, either from Central Admin or by using the PauseCrawl() method in the same way as I have used StopCrawl() above

      Delete
  2. What is the "select name" supposed to be? I have tried the web URL and the Local SharePoint sites and get an error. The search will not stop/ It ha been going for 86 hours!

    ReplyDelete
    Replies
    1. Select name only displays the name of the content source in the PowerShell console. If you really are unable to stop a crawl then you may need to reset the search index, which can be done in Central Admin or by using the script in this article: http://get-spscripts.com/2012/02/resetting-sharepoint-2010-search-index.html

      Delete
  3. Hi,

    In SharePoint 2013 I couldn't stop the Continous Crawl using PowerShell.

    Could you please guide me.

    Thank you

    Sri

    ReplyDelete
    Replies
    1. Same. From what i could gather so far there is no way to do this from powershell. This must be the only thing u can do from the interface but not from powershell.

      Anyone found a way to do it without using the interface?

      Delete
    2. May be it is crazy idea and I do not know whether that will work or not. Anyway is it possible change crawl settings fron continuous to incremental then stop the crawl do something after that. Again switch back to continuous from incremental?

      Is anyone

      Delete
    3. Here's some code to stop the Continuous Crawl

      $SearchApp = "Search Service Application name "
      $IntranetCS = "Content Source Name"
      $ContentSource = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication $SearchApp -Identity $IntranetCS
      $ContentSource.EnableContinuousCrawls = $false
      $ContentSource.Update()

      Delete
  4. sharepoint crawl is running but not stopping. This is happening after we replaced the old SAN storage. Please suggest how to resolve this issue. We stopped few times and tried. No success.

    ReplyDelete
  5. Congratulations, your blog is appealing and informative. Going through your Information, I found quite a few new ideas to implement

    ReplyDelete
  6. I gone through your article It was good keep updating new topics
    SharePoint Online Training

    ReplyDelete
  7. great doing. and i happy to visit your blog to know about this wonderful information. thanks for sharing. keep updating.
    Sharepoint Training in chennai

    ReplyDelete
  8. This is really awesome. Full of knowledge and latest information about web design.Gorilla Online Marketing

    ReplyDelete
  9. The war between humans, orcs and elves continues earn to die . Lead your race through a series of epic battles, using your crossbow to fend off foes and sending out units to destroy castleshappy wheels . Researching and upgrading wisely will be crucial to your success! There are 5 ages total and each one will bring you new units to train to fight in the war for you cause.
    earn to die 2
    Whatever you do, don’t neglect your home base because you cannot repair it and once it is destroyed, you lose! Age of War is the first game of the series and really sets the tone for the Age of War games . Also try out the Age of Defense series as it is pretty similar.
    In this game, you start at the cavern men’s age, then evolvetank trouble ! There is a total of 5 ages, each with its units and turrets. Take control of 16 different units and 15 different turrets to defend your base and destroy your enemy.
    The goal of the game also differs depending on the level. In most levels the goal is to reach a finish line or to collect tokens. Many levels feature alternate or nonexistent goals for the player. The game controls are shown just under gold miner. Movement mechanisms primarily include acceleration and tilting controls. cubefield
    It consists of a total of 17 levels and the challenge you face in each level increases as you go up. unfair mario The game basically has a red ball that has to be moved across the various obstacles in its path to the goal. slitherio

    ReplyDelete
  10. A good blog. Thanks for sharing the information. It is very useful for my future. keep sharing
    red ball 2 | duck life 2 | happy wheels | Red Ball | Red ball 3 | Flash Games| Tank trouble

    ReplyDelete
  11. Wonderful blog! I found it while searching on Yahoo News. Do you have any suggestions on how to get listed in Yahoo News? I’ve been trying for a while but I never seem to get there! Many thanks.
    2048 game | five nights at freddy's 4 | plants vs zombies | five nights at freddy's 3 | fireboy and watergirl | fireboy and watergirl 4||red ball

    ReplyDelete
  12. Nice website, the site is very interesting, a lot of helpful articles and the latest news that arouse interest. nice!!
    obat penghilang kista coklat tradisional
    obat penghilang polip hidung tradisional
    obat penghilang gondongan tradisional

    ReplyDelete