How to Reindex a SharePoint Site using PowerShell?

Requirement: Reindex SharePoint Site collection using PowerShell.

Reindex feature introduced in SharePoint 2013 on wards allows you to force the search service to re-index the whole site, list or library (doesn't matters items are changed or not). By default, the full crawl picks up all items, however when you reindex, SharePoint marks the Items for re-crawl and they will be crawled during the next incremental or continuous crawl.

How to Reindex a SharePoint Site?
To reindex a site, Go to: Site Settings >> Click on "Search and Offline Availability" under search,  Click on "Reindex site" button in reindex site section.
how to reindex the sharepoint site
Confirm the prompt to re-crawl.
sharepoint reindex site powershell
Please note, the reindex is scoped at site level (web). In order to reindex the whole site collection in SharePoint, you have to repeat these steps for each sub-site! (don't panic! We've PowerShell!!)

Reindex SharePoint Site using PowerShell
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

#Get the web
$Web = Get-SPWeb "http://intranet.crescent.com/"
    
[Int] $SearchVersion = 0

#Get the existing search version number
If($Web.AllProperties.ContainsKey("vti_searchversion") -eq $True)
{
    $SearchVersion = $Web.AllProperties["vti_searchversion"]
}

#Increment Search version
$SearchVersion++
 
$web.AllProperties["vti_searchversion"] = $SearchVersion
$web.Update()

Write-host -f Green "Search Version has been increased to :"$SearchVersion

PowerShell to Reindex a SharePoint Site Collection
Here is the PowerShell for SharePoint to reindex site collection.
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

#Site collection URL variable
$SiteURL="http://intranet.crescent.com/"

#Iterate through each web in the site collection
Get-SPSite $SiteURL | Get-SPWeb -Limit All | ForEach-Object {
        
    [Int] $SearchVersion = 0

    #Get the existing search version number
    If($_.AllProperties.ContainsKey("vti_searchversion") -eq $True)
    {
        $SearchVersion = $_.AllProperties["vti_searchversion"]
    }

    #Increment Search version
    $SearchVersion++
 
    #Update the Search version number
    $_.AllProperties["vti_searchversion"] = $SearchVersion
    $_.Update()

    Write-host -f Green "Search Version has been increased to $SearchVersion on $($_.URL)"
}

To reindex site in SharePoint Online using PowerShell, refer: SharePoint Online: How to Trigger Full Reindex using PowerShell?
How to Reindex a SharePoint Site using PowerShell? How to Reindex a SharePoint Site using PowerShell? Reviewed by Salaudeen Rajack on March 14, 2018 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.