Today, we’re going to have another quick look at the wonderful world of PowerShell and how the PnP PowerShell cmdlets make our life a lot easier when administrating SharePoint Online.

I had a couple of site collections that needed to have their Site Collection Search Settings updated to use a dedicated Search Center. While it would be possible to manually go into each site collection and update the settings, this is obviously a bit tedious:

So, what I wanted to do is to automate the process of setting the Search Center URL as well as configuring the search results settings to point to a dedicated Results page url.

The relevant configuration settings are actually stored in the property bag of the root web in a site collection. The Search Center url is stored in SRCH_ENH_FTR_URL_SITE and the results page settings are stored in SRCH_SB_SET_SITE (yes, one property for all settings; however, the syntax is simple, as seen in the code below). And yes, there’s a cmdlet to set a property bag value, it’s called Set-PnPPropertyBagValue. So all we need to do is connect to our site collection and set these two values, done. In my case, as I had to update multiple site collections, I create a simple loop to perform the action on all of them.

 

Here’s the simple code to achieve this:

$cred = Get-Credential
Connect-PnPOnline -Url https://mytenant.sharepoint.com/sites/mydemosite -Credentials $cred
Set-PnPPropertyBagValue -Key SRCH_ENH_FTR_URL_SITE -Value "/search/Pages"
Set-PnPPropertyBagValue -Key SRCH_SB_SET_SITE `
   -Value '{"Inherit":false,"ResultsPageAddress":"/search/Pages/results.aspx","ShowNavigation":false}'

 

And here’s the result after executing these few lines of code

 

6 thoughts on “Setting SharePoint Online Site Collection Search Settings with PowerShell”

Leave a Reply

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