Home > PowerShell, SharePoint 2010 > Setting SharePoint 2010 Site Collection Search Settings using PowerShell

Setting SharePoint 2010 Site Collection Search Settings using PowerShell

I needed to modify the Site Collection Search Settings for all my Site Collections in my SharePoint 2010 web application to enable custom scopes by specifying a Search Center URL, and to also change the Site Collection Search Dropdown Mode to use “Show scopes dropdown”.  Instead of having to go to each Site Collection to check these settings I turned to PowerShell to iterate through all my Site Collections to set these parameters.  Below is the script I used to accomplish this.

This script assumes that the Search Center URL is null.

Different Parameters you can set for the Site Collection Search Dropdown Mode [SRCH_SITE_DROPDOWN_MODE]

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

Parameter you can use to change the Site Collection Search Result Page

[“SRCH_TRAGET_RESULTS_PAGE] i.e $web.AllProperties[“SRCH_TRAGET_RESULTS_PAGE”] = “/_layouts/OSSSearchResults.aspx”

Since my Search Settings already had the [“SRCH_TRAGET_RESULTS_PAGE”] parameter set correctly I did not need to update it or add it in my script, but I doesn’t hurt.

==============================================================

$webApp = Get-SPWebApplication http://portal | Get-SPSite -Limit All

foreach ($site in $webApp)
{

$web = Get-SPWeb $site.Url

if ($web.AllProperties[“SRCH_ENH_FTR_URL”] -eq $null) #Checks to see if the Search Center URL is null, if Yes, set parameters, and update settings.
{
$web.AllProperties[“SRCH_ENH_FTR_URL”] = “/search/Pages/” #Sets the Search Center URL
$web.AllProperties[“SRCH_SITE_DROPDOWN_MODE”] = “ShowDD” #Sets the Site Collection Search Dropdown Mode
$web.Update #Update Search Settings
}

}

===============================================================

Advertisements
  1. haydenhancock
    February 21, 2013 at 8:27 pm

    I can’t get the result’s page to work properly. The results page is set, however, the “Use the same results page settings as my parent” is checked instead of the option to “Send queries to a custom results page URL.

    • February 21, 2013 at 8:57 pm

      Hi Hayden can you show me the script you are using to set the Search Settings? I can take a look and see what you are trying to do.

      • haydenhancock
      • February 22, 2013 at 8:59 am

        Try changing

        $web.AllProperties[“SRCH_TARGET_RESULTS_PAGE”] = “http://mydomain.com/SearchCenter/Pages/results.aspx

        to

        $web.AllProperties[“SRCH_TRAGET_RESULTS_PAGE”] = “http://mydomain.com/SearchCenter/Pages/results.aspx

        Notice the misspelling for TARGET. This is by default not accident, and it needs to be TRAGET for this to work. This misspelling was overlooked by QA in Microsoft in SP2010.

        Let me know if this fixes your problem.

  1. No trackbacks yet.

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

%d bloggers like this: