Wednesday, November 23, 2016

Start a full crawl of a ContentSource in SharePoint 2013 using PowerShell


$snapin = Get-PSSnapin | Where-Object { $_.Name -eq "Microsoft.SharePoint.Powershell" }
if ($snapin -eq $null) {
    Write-Host "[INIT] Loading SharePoint Powershell Snapin"
    Add-PSSnapin "Microsoft.SharePoint.Powershell"
}
 
$searchApp = 
    Get-SPEnterpriseSearchCrawlContentSource -SearchApplication "Search Service Application" | 
    Where-Object { $_.Name -eq "Local SharePoint sites" }
 
if($searchApp.CrawlState -eq "Idle") {
    Write-Host "CrawlState was Idle, crawling Full" -ForegroundColor Green
    $searchApp.StartFullCrawl()
 
    Do {
        Write-Host "`r#" -ForegroundColor Yellow -NoNewline
        Start-Sleep 5
    } while ($searchApp.CrawlState -ne "Idle")
 
    Write-Host "`nFinsihed crawling" -ForegroundColor Green
 
} else{
    Write-Host "Didn't start crawl, CrawlState was"$searchApp.CrawlState -ForegroundColor Yellow
}

Stop and then start a full crawl on all content sources using PowerShell
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()
}



Start a full crawl of a ContentSource in SharePoint 2013 using PowerShell


$snapin = Get-PSSnapin | Where-Object { $_.Name -eq "Microsoft.SharePoint.Powershell" }
if ($snapin -eq $null) {
    Write-Host "[INIT] Loading SharePoint Powershell Snapin"
    Add-PSSnapin "Microsoft.SharePoint.Powershell"
}
 
$searchApp = 
    Get-SPEnterpriseSearchCrawlContentSource -SearchApplication "Search Service Application" | 
    Where-Object { $_.Name -eq "Local SharePoint sites" }
 
if($searchApp.CrawlState -eq "Idle") {
    Write-Host "CrawlState was Idle, crawling Full" -ForegroundColor Green
    $searchApp.StartFullCrawl()
 
    Do {
        Write-Host "`r#" -ForegroundColor Yellow -NoNewline
        Start-Sleep 5
    } while ($searchApp.CrawlState -ne "Idle")
 
    Write-Host "`nFinsihed crawling" -ForegroundColor Green
 
} else{
    Write-Host "Didn't start crawl, CrawlState was"$searchApp.CrawlState -ForegroundColor Yellow
}

or 

Stop and then start a full crawl on all content sources using PowerShell

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()
}


courtesy