Activate SharePoint Global Search on Hub sites

The Hub sites that are connected on SharePoint (hubify), by default will have the search made on the particular site that the users connects. Making the search on those SharePoint sites to be global can make the life easier of your employees to find documents on the Intranet. On this article, we’ll provide a PowerShell script that makes all the sites of that particular Hub to have the Search globally activated.

For now, to activate this feature you need to run this PowerShell script, however, Microsoft will provide a way to set this setting using the UI later this year. It’s possible they provide this option per site. If you don’t have permissions, it’ll show the sites that you didn’t have permissions to activate this feature. You can then send them the PowerShell to activate on that particular site. You can check that script on the next link.

$tenantAdmin = ""
$hubSite = ""

 Connect-PnPOnline -Url $tenantAdmin -UseWebLogin
} catch {
 Write-Host "Unable to connect."
$HubSite = Get-PnPHubSite $hubSite
$HubSiteId = $HubSite.SiteId
$ModernSites = (Get-PnPTenantSite -Template 'GROUP#0') + (Get-PnPTenantSite -Template 'SITEPAGEPUBLISHING#0')
$SitesFromHub = New-Object System.Collections.ArrayList
Write-Host ("Searching {0} sites:" -f $HubSite.Title) -BackgroundColor Gray
 foreach ($ModernSite in $ModernSites){
  $site = Get-PnPHubSite $ModernSite.Url
   if($site.SiteId -eq $HubSiteId){
    Write-Host ("* {0} - {1}" -f $ModernSite.Title, $ModernSite.Url)
    $SitesFromHub.Add($ModernSite) | Out-Null
Write-Host ""
Write-Host "Activating search global at:" -BackgroundColor Gray
foreach ($SiteHub in $SitesFromHub){
  Write-Host ("* {0} - {1} ... " -f $SiteHub.Title, $SiteHub.Url) -NoNewline	
  Connect-PnPOnline -Url $SiteHub.Url -UseWebLogin
  $web = Get-PnPWeb
  #1 to activate Global Search and 0 to deactivate Global Search
  $web.SearchScope = 1
  Write-Host "Done" -BackgroundColor Green	
   Write-Host "No permission" $site.url -BackgroundColor Red	
Write-Host "All Done"
Write-Host "Press any key to Close..."


Regardless of the site where you’re user is connected, they will have access to all documents stored on intranet on the search area and avoid to go on a specific site to search a document.


  1. HLJ said:

    Hello David,
    This is a great post and script.
    But wondering, if I go the the search window and then click SITES – Search for NAME OF SITE / DOCUMENT / CONTENT – in all content doesn’t that do the same thing? I was able to find the content I wanted. Although granted it is about 2 additional clicks.

    May 8, 2019
    • David Ramalho said:


      The idea is to make easier your users find the specific content and this configuration can help on that task. This will come to the point where you need to decide which option between site and global search is better for the end-user.

      Thank you for your feedback and have a great day!!

      May 13, 2019
  2. Nikhil said:

    Hello David,

    Thank you for the great post, it helped a lot !

    I was wondering if this can be possible to access only two sites instead of accessing the entire sharepoint site pages. As a hub site from here i want to access only two sites(tenant sites)?

    Thanks and Regards,

    July 19, 2019
    • David Ramalho said:

      Hi Nikhil,

      I don’t think is possible to have the search on SharePoint to search only on the site (Site A) and another site (Site B). You need to select the search global (A, B, C, etc) when searching or just on the site (A).

      July 20, 2019
      • Nikhil said:

        Thank you for the reply, for example I have requirement like I have hub site underneath that I have A,B,C sites. As a requirement I need to search only A and B but not C. As per your comments it is possible only by global search which will search entire share point ?

        July 20, 2019
        • David Ramalho said:

          Yes, that is correct.

          July 21, 2019

Leave a Reply

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