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 the Full crawl fully indexes items in SharePoint on the schedule, Reindex feature in SharePoint helps to recrawl and perform full indexing during the next incremental or continuous crawl. This blog post will show you how to reindex a SharePoint Online list or library. Maybe it was because the search wasn’t returning the results you were expecting, or perhaps new documents weren’t showing up in the library. In any case, if you need to reindex a list or library, PowerShell is the way to go.

#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 another post for SharePoint On-premises: How to Reindex SharePoint List or Document Library?

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 *