Apr 12 2019 11:32 AM - edited Apr 08 2020 04:49 PM
Hey everyone,
We heard from many of you the need to be able to change the scope of your modern search results pages. When you create a new communication site or team site in SharePoint Online today, and type into the search box, you are taken to the modern search results page. This page shows results from your current site by default, and allows you to expand the scope of your search to the hub that the current site is associated with (if there is one), or to the whole organization.
But there is a desire for being able to change the behavior to always search over the whole organization, or across the hub a site is associated with, without needing an additional click, especially if the site in question will be used as a modern landing page for your organization.
I'm happy to say that with the latest version of the SharePoint PnP PowerShell extensions, it is possible to run a simple command as the site owner, and make your site use the organization, or the hub scope by default.
To change this setting:
1. Start PowerShell in administrator mode as you will be installing the PnP extensions.
2. Run the following commands to in this order:
PS C:\WINDOWS\system32> Install-Module SharePointPnPPowerShellOnline
# If you previously had installed this module, you may need to use the "-Force" parameter to install the newer version.
PS C:\WINDOWS\system32> Connect-PnPOnline -Url https://contosodemosg.sharepoint.com/sites/Strategy -UseWebLogin
# this will prompt you to sign into your site. Use the site owner credentials to sign in
PS C:\WINDOWS\system32> $web = Get-PnPWeb PS C:\WINDOWS\system32> $web.SearchScope = 1
# 1 for Tenant, 2 for Hub, 3 for Site, 0 for default behavior
PS C:\WINDOWS\system32> $web.Update() PS C:\WINDOWS\system32> Invoke-PnPQuery
After running these commands, the site will start to show results from the whole organization.To go back to the default setting, run the commands again with the value provided to "SearchScope" parameter to 0.
To search across the Hub, use 2 as the SearchScope value.
We will be providing a way to set this setting using the UI in a future release as well.
Updated in April 2020 to reflect the ability to search across Hubs.
Apr 12 2019 01:08 PM
Apr 14 2019 07:12 AM
Apr 14 2019 11:39 AM
Hi @Robert Schouten, not right away, but some of my colleagues are working on adding the ability to set properties and turn on features. Hopefully that will be available later this year.
Apr 14 2019 11:40 AM
SolutionHi @Rick DeFoe, we are actually working on making that happen. We hope that will be coming in the next couple of months.
Apr 15 2019 12:18 AM
@Robert Schouten, in the meanwhile you could make the site script to start a flow and from that flow call an Azure function that runs the PowerShell script.
Laura
Apr 15 2019 12:53 AM
@Laura Kokkarinen yes I know that road. At some customers, an Azure environment is not always available. But if it is, it a very valid option! Tnx...
Apr 15 2019 02:13 AM
Apr 15 2019 05:06 AM
Thank you for adding this feature. Often requested by our customers. Just tried it out and worked directly as I expected.
Apr 15 2019 05:31 AM - edited Apr 15 2019 05:31 AM
Optional easy way: Create a Link to your Navigation Bar -> https://YourTenantName.sharepoint.com/_layouts/15/sharepoint.aspx?&v=search
Apr 16 2019 07:51 AM
@Kerem Yuceturk This looks great! I am trying to implement it and run into an issue when trying to connect to the site. We have single sign on enabled via SailPoint and when the browser goes to try and log me in I get a blinking screen and cannot get connected. Any suggestions?
Apr 17 2019 06:09 AM
@Kerem Yuceturk It seems that searching trough the REST API, this setting is ignored.
This query for example, searches only in the current sitecollection on a modern communication site:
https://mytenant.sharepoint.com/sites/moderncommunicationsite/_api/search/query?querytext=%27test%27
See also this issue:
Apr 17 2019 06:10 AM
@Kerem Yuceturk It seems that searching trough the REST API, this setting is ignored.
This query for example, searches only in the current site collection on a modern communication site:
https://mytenant.sharepoint.com/sites/moderncommunicationsite/_api/search/query?querytext='test'
See also this issue:
Apr 17 2019 01:32 PM
Even though the search api of the site is used you still can be able to get tenant wide results.
When doing a site scoped search we scope by limiting the search in the query template of the query with Path:"UrlToCommunicationSite". And when upscoping this path part of querytemplate is removed.
So you should still be able to get tenant wide results even if the search api of the communicationsite is used to post the query.
Are you only seeing results from your communicationsite after changing the site scope?
Apr 17 2019 03:53 PM
@Joe Volk , sorry not familiar with that. My two factor auth works when I use -UseWebLogin. This page has more information about the PnP solution, and may have some discussions that might be helpful: https://github.com/SharePoint/PnP-PowerShell
Apr 17 2019 03:54 PM
Hi @Renevdo, This is for the modern search results UI only. It has no effect on REST. You should be able to get to the scope that you want in REST in other ways like as @Geir-Magnus Pettersen mentioned!
Apr 23 2019 07:11 PM
I noticed that the search box placeholder does not change on hub sites, see screenshots:
Hub search box:
All other sites:
Will this be fixed/updated so that the placeholder is consistent across hub and non-hub sites?
May 09 2019 08:05 PM
I follow the directions step by step and i am getting error:
The property 'SearchScope' cannot be found on this object. Verify that the property exists and can be set.
Have the latest version of powershell.
Anyone seen this error?
Thanks
May 17 2019 03:32 PM
I'm receiving the same error. I've made sure I'm running PowerShell in Admin mode as well. Forced the re-installation of module as well as tried update. No luck, any help is appreciated!
May 19 2019 07:05 AM
Some additional guidance if you are getting the "The property 'SearchScope' cannot be found on this object. Verify that the property exists and can be set."
Exception when you try to execute the version, you are running either wrong version of PnP PowerShell OR you have SharePoint CSOM SDK installed on your machine which is not recommended.
If you have just updated to use the latest PnP PowerShell, move to "Add or Remove programs" in your computer and make sure that you do not have SharePoint Client Side CSOM SDK installed as that msi unfortunately installed assemblies to the GAC (Global Assembly Cache) and that overrides any local newer assembly versions, which is most likely the conflict here.
Apr 14 2019 11:40 AM
SolutionHi @Rick DeFoe, we are actually working on making that happen. We hope that will be coming in the next couple of months.