SharePoint Full Crawl Stuck? Force Stop SharePoint Search Crawl using PowerShell
Problem: SharePoint 2013 search crawl process is running infinitely! And crawl was not stopping!!
Solution:
I tried stopping the crawl process from the search administration page of SharePoint 2013 central administration but failed.
PowerShell to rescue! This script checks whether the crawler status is “Idle” for the given content source. If not, it stops the crawl activity and waits until the status is changed to idle.
Stop Search Crawl for All Content Sources:
Here is how to stop the search crawl for all content sources in SharePoint using PowerShell.
#Stop the crawl for all content sources
Get-SPEnterpriseSearchCrawlContentSource -SearchApplication "Search Service Application" | ForEach-Object {
If($_.CrawlStatus -ne "Idle")
{
Write-Host "Stopping crawl on Content source $($_.Name)..."
$_.StopCrawl()
While ($_.CrawlStatus -ne "Idle")
{
Write-Host "Waiting to crawl to be stopped..." -f DarkYellow
sleep 3
}
write-host "Crawl Stopped Successfully!" -f DarkGreen
}
else
{
write-host "Crawl Status of the Content source '$($_.Name)' is Idle!" -f DarkGreen
}
}
PowerShell script to force stop SharePoint 2013 search crawl on specific content source:
To stop Search crawl forcefully in SharePoint, use this script.
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
#Content source Name
$ContentSourceName= "Crescent Portal" #default "Local SharePoint sites"
#Get the search service application
$SSA = Get-SPEnterpriseSearchServiceApplication #-Identity "Search Service Application Name"
#Get the content source
$ContentSource = $SSA | Get-SPEnterpriseSearchCrawlContentSource -Identity $ContentSourceName
#Check if Crawler is not already running
if($ContentSource.CrawlState -ne "Idle")
{
Write-Host "Stopping Crawl..."
$ContentSource.StopCrawl()
#Wait till its stopped
while($ContentSource.CrawlState -ne "Idle")
{
Write-Host "Waiting to crawl to be stopped..." -f DarkYellow
sleep 5
}
write-host "Crawl Stopped Successfully!" -f DarkGreen
}
else
{
Write-Host "Search Crawl is not running!" -f Red
}
Disable continuous crawl for all SharePoint content sources
$SSA =Â Get-SPEnterpriseSearchServiceApplication
$ContentSources = $SSA | Get-SPEnterpriseSearchCrawlContentSource | Where{$_.Type -eq "SharePoint"}
foreach ($cs in $ContentSources)
{
 $cs.EnableContinuousCrawls = $false
 $cs.Update()
}
I used this script when the crawler was stuck in the stopping state! Related post: Start SharePoint Search Crawl using PowerShellÂ
Very good, thanks
Very Helpful! Thanks