Trigger a Full Crawl on SharePoint Online

alt

Mikael Svenson wrote a cool script which will iterate all site collections, sites and sub-sites on your tenant to force a trigger of re-indexing / full crawl of all items on the next crawl.

In SharePoint Online we cannot force a full crawl via the admin user interface and thus have to iterate all sites and set a property in the property bag to accomplish the same task:


function processWeb($web) {

    $subWebs = $web.Webs
    $clientContext.Load($web)     
    $clientContext.Load($web.AllProperties)
    $clientContext.Load($subWebs)
    $clientContext.ExecuteQuery()

    Write-Host "Web URL:" $web.Url -ForegroundColor White
    if( $enableAllManagedProperties -ne "skip" ) {
        Set-AllManagedProperties -web $web -clientContext $clientContext -enableAllManagedProps $enableAllManagedProperties
    }

    [int]$version = 0
    $allProperties = $web.AllProperties
    if( $allProperties.FieldValues.ContainsKey("vti_searchversion") -eq $true ) {
        $version = $allProperties["vti_searchversion"]
    }
    $version++
    $allProperties["vti_searchversion"] = $version
    Write-Host "-- Updated search version: " $version -ForegroundColor Green
    $web.Update()
    $clientContext.ExecuteQuery()

    foreach ($subWeb in $subWebs)
    {
        processWeb($subWeb)
    }
}

This is needed for several search schema modifications, for example when you map crawled properties to managed properties.

The script also has a function to enable population of the ManagedProperties managed property for use with the SharePoint 2013 Search Query Tool v2.

You can download the script here: https://github.com/wobba/SPO-Trigger-Reindex

Get in Touch!

Matthew Stark

Founder, Making Things Work

Let's talk about your project & how I can help! Reach out at the below coordinates.

Connect on Linkedin read more about Matt »

Top Tags