SharePoint Online: How to Reindex a List or Document Library using PowerShell?

Requirement: SharePoint Online Reindex list or document library using PowerShell

PowerShell to Reindex a List or Document Library in SharePoint Online

PowerShell to Reindex List in SharePoint Online

Although Items are fully indexed by Full crawl in SharePoint, Reindex feature in SharePoint helps to recrawl and perform full indexing during the next incremental or continuous crawl.

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Variables for Processing
$SiteUrl = ""

#Setup Credentials to connect
$Cred = Get-Credential
Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
    #Get the List Root Folder

    [Int] $SearchVersion = 0
    #Get the existing search version number
    If($List.RootFolder.Properties.FieldValues.ContainsKey("vti_searchversion") -eq $True)
        $SearchVersion = $List.RootFolder.Properties["vti_searchversion"]
    #Increment Search version

    #Update the Search version number
    $List.RootFolder.Properties["vti_searchversion"] = $SearchVersion
    Write-Host -f Green "Search Version Set to '$SearchVersion' and List '$ListName' marked for Reindex Successfully!"
Catch {
    write-host -f Red "Error:" $_.Exception.Message

PnP PowerShell to Reindex a List in SharePoint Online:

Here is the PnP PowerShell to reindex a SharePoint Online list or library

#Config Variables
$SiteURL = ""

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Request Reindex
Request-PnPReIndexList -Identity $ListName 

Here is my another post written for SharePoint On-premises: How to Reindex SharePoint List or Document Library?

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

Leave a Reply