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

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

原文地址:https://www.cnblogs.com/love007/p/2565678.html