How to Reindex a SharePoint Site using PowerShell?

Requirement: Reindex SharePoint Site collection using PowerShell.

Reindex feature introduced in SharePoint 2013 onwards allows you to force the search service to re-index the whole site, list, or library (it doesn’t matter whether 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, and click on the “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 the site level (web). To reindex the whole site collection in SharePoint, you have to repeat these steps for each subsite! (don’t panic! We’ve PowerShell.)

Reindex SharePoint Site using PowerShell

Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

#Get the web
$Web = Get-SPWeb "https://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="https://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 a site in SharePoint Online using PowerShell, refer: SharePoint Online: How to Trigger Full Reindex using PowerShell?

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

Leave a Reply

Your email address will not be published. Required fields are marked *