Update Search Settings using Powershell in SharePoint 2013

In many scenarios where you have to build up a complex Information Architecture in SharePoint, you will also have to set the Search Settings for each site or site collection to point to your search center and your custom results page.

search-config

In SharePoint 2013 the search settings have become a little bit more complex, therefore we need a new script to set them. Below you will find two powershell functions: one that sets the search settings for the entire site collection and one just for a specific web.

function SetSearchSettingsSite($siteUrl,$searchCenterUrl,$resultPagesUrl)
{
$site = Get-SPSite $siteUrl
$site.AllWebs | ForEach-Object {
$web = $_
$web.AllProperties[“SRCH_SB_SET_WEB”] = ‘{“Inherit”:false,”ResultsPageAddress”:”‘+$resultPagesUrl+'”,”ShowNavigation”:false}’
$web.AllProperties[“SRCH_ENH_FTR_URL_WEB”] = $searchCenterUrl $web.Update()
}
}
function SetSearchSettingsWeb($siteUrl,$searchCenterUrl,$resultPagesUrl)
{
$web = Get-SPWeb $siteUrl
$web.AllProperties[“SRCH_SB_SET_WEB”] = ‘{“Inherit”:false,”ResultsPageAddress”:”‘+$resultPagesUrl+'”,”ShowNavigation”:false}’
$web.AllProperties[“SRCH_ENH_FTR_URL_WEB”] = $searchCenterUrl
$web.Update()
}
SetSearchSettingsSite http://spdevel.portal.com/ http://spdevel.portal.com/search http://spdevel.portal.com/search/Pages/Results.aspx

The second part of the search settings has been integrated in a single web property – “SRCH_SB_SET_WEB”, as a representation of a SharedSearchBoxSettings object. This script only sets the search settings at site-level. If you want to configure the search settings at site-collection level or at farm-level, it would be slightly different. At site-collection level, you would need to set the root web property “SRCH_SB_SET_SITE”, and for farm-level, you would need to set the SharedSearchBoxSettings and SearchCenterUrl properties of the Search Service Application

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s