in SharePoint 2010

Start Search Crawl using PowerShell

Below is a PowerShell function that will query for all the search scopes (including FAST search scopes) from the default enterprise search service application (and FAST service application) and starts a full crawl. The script also waits for the crawl to be completed:

function StartCrawl()
{
    $searchScopes = Get-SPEnterpriseSearchServiceApplication 
                                        | Get-SPEnterpriseSearchCrawlContentSource

    foreach($searchScope in $searchScopes)
    {
        $name = $searchScope.Name

        if($searchScope.CrawlState -eq "Idle")
        {
            Write-Host -f Yellow "Starting full crawl for $name"
            $searchScope.StartFullCrawl();
            sleep 5


            while($searchScope.CrawlState -eq "Idle")
            {
                Write-Host -f Yellow "waiting to crawl $name ..."
                sleep 5
            }

            Write-Host

            while($searchScope.CrawlState -eq "CrawlStarting")
            {
                Write-Host -f Magenta "starting to crawl crawling $name ..."
                sleep 5
            }

            Write-Host

            while($searchScope.CrawlState -eq "CrawlingFull")
            {
                Write-Host -f White "crawling $name ..."
                sleep 5
            }

            Write-Host

            while($searchScope.CrawlState -eq "CrawlCompleting")
            {
                Write-Host -f DarkMagenta "stopping to crawl $name ..."
                sleep 5
            }

            Write-Host -f Green "crawl is complete for $name"
            Write-Host
        }
    }
}

$searchScope.StartIncrementalCrawl(); will start an incremental crawl.

Visit here to know more about configuring Search Service Application using PowerShell

Write a Comment

Comment

Time limit is exhausted. Please reload the CAPTCHA.