kwizcom banner advertisement

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 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 = "https://crescenttech.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:
Here is the PnP PowerShell to reindex a SharePoint Online list or library
#Config Variables
$SiteURL = "https://crescenttech.sharepoint.com"
$ListName="Projects"

#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?
SharePoint Online: How to Reindex a List or Document Library using PowerShell? SharePoint Online: How to Reindex a List or Document Library using PowerShell? Reviewed by Salaudeen Rajack on April 17, 2018 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.