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

How to Reindex a List or Document Library in SharePoint Online?

Reindexing a list or document library in SharePoint Online can be necessary when you are experiencing search issues, such as missing items or incomplete search results. Reindexing can help to rebuild the search index and ensure that all content is properly indexed and searchable. In this article, we will explain how to reindex a list or document library in SharePoint Online, providing step-by-step instructions and PowerShell.

Step 1: Navigate to the List or Library Settings

To begin, navigate to the list or library that you want to reindex and click on the gear icon in the upper-right corner. Select “List Settings” or “Library Settings” from the dropdown menu.

Step 2: Reindex the List or Library

Once you are in the list or library settings, scroll down to the “General Settings” section and click on “Advanced settings”. Under “Reindex Document Library” or “Reindex List”, click on the “Reindex” button to initiate the reindexing process.

reindex sharepoint online list document library

By following these steps, you can reindex a list or document library in SharePoint Online. This can help to ensure that all content is properly indexed and searchable, reducing the risk of missing items or incomplete search results. After the reindexing process is complete (probably in six hours), you should verify that the search results are accurate and complete.

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 = "https://Crescent.sharepoint.com"
$ListName="Projects"

#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
    $List=$Ctx.web.Lists.GetByTitle($ListName)
    $Ctx.Load($List)
    $Ctx.Load($List.RootFolder)
    $Ctx.Load($List.RootFolder.Properties)
    $Ctx.ExecuteQuery()

    [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
    $SearchVersion++

    #Update the Search version number
    $List.RootFolder.Properties["vti_searchversion"] = $SearchVersion
    $List.RootFolder.Update()
    #$List.Update()
    $Ctx.ExecuteQuery()
    
    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

Use the PnP PowerShell cmdlet Request-PnPReIndexList to reindex a SharePoint Online list or library:

#Config Variables
$SiteURL = "https://Crescent.sharepoint.com"
$ListName="Projects"

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

#Request Reindex
Request-PnPReIndexList -Identity $ListName 

How about reindexing a site in SharePoint Online? Here is how: How to Reindex a SharePoint Online site?

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

Leave a Reply

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