Skip to content

Update Multiple SharePoint Online Sites to Search Whole Tenant

Recently, Microsoft has refocused their efforts on search across Office 365 through various initiatives like Microsoft Search. One of those changes is a persistent search bar in the Suite Bar as pictured below. However, up until recently you could only search the current site from that search bar, which is very disappointing.

Notice the hint text says “this site”

Thankfully, Microsoft has recently enabled through PowerShell (UI forthcoming) the ability to change the scope of this search input to be tenant wide. The script Microsoft shared only works for one site though, and when you want to do it for an entire intranet, no one wants to run that script for every site.

Since I am not the one to trust with PowerShell, my colleague Arya Parsee put together the following script to update as many site collections as desired from a CSV file.

$csvFile = "C:\file.csv"
$creds = Get-Credential
$table = Import-Csv $csvFile -Delimiter ","
Write-Host "Begin"
foreach ($row in $table)
  Write-Host  $row.SiteCollection
  Connect-PnPOnline -Url $row.SiteCollection -Credentials $creds 
  $web = Get-PnPWeb
  $web.SearchScope = 1 
Write-Host "End"

As mentioned the script needs to point to a CSV so create a CSV with the following format pictured below, and change the first line of the script to point to that file.

The last things to remember are to run PowerShell as an administrator, make sure the account that you authenticate to run the script has necessary permissions, and I would suggest make a .ps1 file out of the script and running in PowerShell.

After running your script, the search box will update!

Note the hint text now says it will search all of SharePoint
Leave a Reply

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