SharePoint Online: Change Default Search Scope from “Search This Site” to “Search All Sites”

Requirement: Configure Search Scope in SharePoint Online.

How to Change the Default Search Scope in SharePoint Online?

The default search scope in SharePoint Online is “Search this site” that allows us to search inside the specific site collection.

sharepoint online set search scope

PowerShell to Configure Search Scope in SharePoint Online

We can change default search scope in SharePoint Online using PowerShell script:

#Set Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/Marketing"

#Get 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 Web object
    $Web = $Ctx.Web
    $Ctx.Load($Web)
    $Ctx.ExecuteQuery()

    #Set search scope for the web to global
    $Web.SearchScope = 1
    $web.Update()
    $Ctx.ExecuteQuery()
}
Catch {
    write-host -f Red "Error:" $_.Exception.Message
}

This changes the search scope for a given SharePoint Online site from “Search this site” to “Search in SharePoint” (Global search).

sharepoint online change default search scope

Search scope enumeration values:

  • DefaultScope = 0
  • Tenant = 1
  • Hub = 2
  • Site = 3

Configure search scope in SharePoint Online using PnP PowerShell

We can also set search scope using PnP PowerShell.

#Set Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/Marketing"

#Connect to SharePoint Online site
Connect-PnPOnline -Url $SiteURL -UseWebLogin

#change default search scope
Set-PnPSearchSettings -SearchScope Tenant

This will change the search scope from local site to global search. If you want to update multiple site collections, you can either loop through them and apply this settings or use a CSV file to selectively change search scopes.

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!

2 thoughts on “SharePoint Online: Change Default Search Scope from “Search This Site” to “Search All Sites”

  • May 29, 2021 at 4:34 AM

    Hello, is there a solution to do this in an on premise installation too (SharePoint 2019 Server)

    Reply
  • January 7, 2021 at 9:09 AM

    I did the above procedure but the problem is Scroll is now disabled on search page after changing the scope to global.

    Reply

Leave a Reply