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 = ""

#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

    #Set search scope for the web to global
    $Web.SearchScope = 1
Catch {
    write-host -f Red "Error:" $_.Exception.Message
This changes the search scope for 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 = ""

#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.

1 comment:

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


Please Login and comment to get your questions answered!

Powered by Blogger.