SharePoint 2010 How to Change the Search Settings In a Site Collection using PowerShell

By walter.munoz on August 19th, 2011

The following script sets the Site Collection Search Center, Stie Collection Dropdown Mode and Site Collection Search Results Page for all Site Collections that are not a Search Center in the Web Application.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#Search Center URL
$searchURL = "/searchcenter/Pages/results.aspx"
#Get the Web Application
$webApplication = Get-SPWebApplication "<a href="http://alvsptw03:11682&quot;">http://localhost"</a>
 
#loop through the sites in the web application
foreach ($site in $webApplication.Sites)
{
      #Get the root web
      $web = $site.RootWeb
      #We want to update all sites that are not a search center
      if ($web.WebTemplate -ne "SRCHCEN")
      {
         #Site Collection Search Center
         $web.AllProperties["SRCH_ENH_FTR_URL"] = $searchURL
 
         #Site Collection Search Dropdown Mode
         #Show scopes Dropdown = ShowDD
         $web.AllProperties["SRCH_SITE_DROPDOWN_MODE"] = "ShowDD"
 
         #Site Collection Search Results Page
         $web.AllProperties["SRCH_TRAGET_RESULTS_PAGE"] = $searchURL
 
         $web.Update()
 
         Write-Host "Updated Search Settings on Site: " $web.Url
 
      }
}

The SRCH_ENH_FTR_URL is the URL or relative path of the Search Center you want to use.

The Drop Down can be set to one of the following values:

Site Collection Search Dropdown Mode

Value

Do you need to set the Sit Collection Search Results Page?

Do Not Show Scopes Dropdown, and default to contextual scope

HideScopeDD_DefaultContextual

YES

Do Not Show Scopes Dropdown, and default to target results page

HideScopeDD

NO

Show scopes Dropdown

ShowDD

YES

Show, and default to ‘s’ URL parameter

ShowDD_DefaultURL

YES

Show and default to contextual scope

ShowDD_DefaultContextual

YES

Show, do not include contextual scopes

ShowDD_NoContextual

NO

Show, do not include contextual scopes, and default to ‘s’ URL parameter

ShowDD_NoContextual_DefaultURL

NO