Set SharePoint Search Settings (Search Center URL, Scope Dropdown Mode) Programmatically

After migrating SharePoint 2007 sites to SharePoint 2010, we decided to set search center URL to a Enterprise Search center site and scope settings Dropdown mode to use “Show scopes dropdown” for all site collections.

To update search center and search scope dropdown settings in SharePoint sites, We used to go:

  • Site Actions >> Site Settings 
  • Click on “Search Settings” under “Site collection Administration”
  • Set search center URL and search scope dropdown
set sharepoint search center URL programmatically powershell

Update SharePoint Search Settings Programmatically:
Alright, How about new site collections which we are going to create down the line? Well, We used this code in a feature stapler to programmatically set SharePoint search center URL:

//Read Search Center URL value from Feature.xml
if (properties.Feature.Properties["SearchCenterURL"] != null)
   string searchCenterURL = properties.Feature.Properties["SearchCenterURL"].Value;
   //Set the Search Center URL
   web.AllProperties["SRCH_ENH_FTR_URL"] = searchCenterURL;

property segment from Feature.xml file:

   <Property Key="SearchCenterURL" Value="" />

Set Search Center URL using PowerShell

To update the Search Settings programmatically, There is no API available, but these values are stored as a part of the property bag of the SPWeb object. For existing sites that are already created prior to deploying this feature, let’s use PowerShell to set search center URL and Search scope dropdown mode:

Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

$WebAppURL = ""
$SearchCenterURL= ""

#Iterate through each site in the given web application
Get-SPWebApplication -Identity $WebAppURL | Get-SPSite -Limit ALL | foreach { 
        $_.RootWeb.AllProperties["SRCH_ENH_FTR_URL"] = $SearchCenterURL
        $_.RootWeb.AllProperties["SRCH_SITE_DROPDOWN_MODE"] = "ShowDD"
        Write-Host "Search settings Updated for "$_.RootWeb.Url -ForeGroundColor DarkGreen

Set SharePoint Search Settings Programmatically using C#:

In another scenario, I wrote a .net C# console application that does the job of updating the search center URL and search scope dropdown mode.

SPWebApplication webApp = SPWebApplication.Lookup(new Uri(""));

foreach (SPSite site in webApp.Sites)
	SPWeb web = site.OpenWeb();

	web.AllProperties["SRCH_ENH_FTR_URL"] = "";
	web.AllProperties["SRCH_SITE_DROPDOWN_MODE"] =    "ShowDD"       ;
	//web.AllProperties["SRCH_TRAGET_RESULTS_PAGE"] = "";
	Console.WriteLine ("Updated Search settings for " + web.Url);

Search Scope Dropdown modes:

Below are the valid values you can use for SRCH_SITE_DROPDOWN_MODE

  • ShowDD – Show scopes dropdown
  • ShowDD_DefaultURL – Show, and default to ‘s’ URL
  • ShowDD_DefaultContextual – Show and default to contextual scope
  • ShowDD_NoContextual – Show, do not include contextual scopes
  • ShowDD_NoContextual_DefaultURL – Show, do not include contextual scopes, and default to ‘s’ URL paramete
  • HideScopeDD_DefaultContextual – Do Not Show Scopes Dropdown, and default to contextual scope
  • HideScopeDD – Do not show scopes dropdown, and default to target results page

For Search Scope Dropdown modes, Refer:

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. Passionate about sharing the deep technical knowledge and experience to help others, through the real-world articles!

Leave a Reply

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