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
Setting SharePoint Online Site Collection Search Settings with PowerShell https://t.co/ldJnGM4wYN #sharepoint #office365
Setting SharePoint Online Site Collection Search Settings with PowerShell . https://t.co/1sGvayqqW7
Setting SharePoint Online Site Collection Search Settings with PowerShell https://t.co/fseze7iX8Y #SharePoint
Setting SharePoint Online Site Collection Search Settings with PowerShell – Rene Modery https://t.co/scTZ7KnR4n https://t.co/RLDDvZURiw
Setting SharePoint Online Site Collection Search Settings with PowerShell – Rene Modery https://t.co/Dhe0my3YJo via… https://t.co/R8UXvXduYy
How do i access the securityTrimEnabled property under SiteNavigationsettings page(htru powershell)
Hi Deepak, also unsure, couldn’t find a way to do so
I could actually get the context for onPrem..
$Context = New-Object Microsoft.SharePoint.Publishing.Navigation.SiteNavigationSettingsWriter($SPWeb.Site)
$Context.SecurityTrimmingEnabled=$FlagValue
SiteNavigationSettingsWriter is not supporting in the Online