Set Site Collection Search Settings by PowerShell

Setting your Site Collection Search Settings by Powershell, what a tongue twister, try saying that six times fast. Setting your search settings via PowerShell is not something that is immediately obvious and requires a bit of digging.

First – how do we see what settings we’ve currently got?  First lets get our web and throw it into a variable to make it a bit easier to handle.

$web = get-spweb http://address

By digging down through the properties of the $web object we can see two areas that might house this : allProperties and Properties.  I do not know why there are two property areas, seems a little confusing.

The properties we are after are in AllProperties and are called :

SRCH_ENH_FTR_URL and SRCH_SITE_DROPDOWN_MODE

SRCH_ENH_FTR_URL is pretty straight forward, it is the URL or relative path of the Search Center you want to use and can be set like follows :

$web.AllProperties[“SRCH_ENH_FTR_URL”] = “http://address.to/searchcenter”

Controlling the drop down is a little more difficult, as there are lots of not too transparent options to pick.  Here they are mapped out :

Site Collection Search Dropdown Mode Property Value Search Results URL
Do Not Show Scopes Dropdown, and default to contextual scope HideScopeDD_DefaultContextual Y
Do Not Show Scopes Dropdown, and default to target results page HideScopeDD N
Show scopes Dropdown ShowDD Y
Show, and default to ‘s’ URL parameter ShowDD_DefaultURL Y
Show and default to contextual scope ShowDD_DefaultContextual Y
Show, do not include contextual scopes ShowDD_NoContextual N
Show, do not include contextual scopes, and default to ‘s’ URL parameter ShowDD_NoContextual_DefaultURL N
It is pretty easy to set this with the following :
$web.AllProperties[“SRCH_SITE_DROPDOWN_MODE”] = HideScopeDD_Defaultcontextual
If a dropdown mode is selected that requires a results URL set, then this can be set using the SRCH_TRAGET_RESULTS_PAGE property.  Please note that this is NOT my typo, this is how it is in the Web AllProperties property.
$web.AllProperties[“SRCH_TRAGET_RESULTS_PAGE”] = “http://address.to/searchcenter/_layouts/OSSSearchResults.aspx”

Nice and easy, and you’ve just set your search settings via PowerShell.  If you are like me, and I’m guessing you will be, you’ll be doing a $web.update() just to finish this off and write all the settings back to the site.

Here is the full script, please note it assumes you have loaded Microsoft.SharePoint.PowerShell

$web = Get-SPWeb http://www.address.com
$web.AllProperties[“SRCH_ENH_FTR_URL”] = “/search/”
$web.AllProperties[“SRCH_SITE_DROPDOWN_MODE”] = HideScopeDD_Defaultcontextual
$web.AllProperties[“SRCH_TRAGET_RESULTS_PAGE”] =”/_layouts/OSSSearchResults.aspx”
$web.update()
Advertisement

12 Responses to Set Site Collection Search Settings by PowerShell

  1. Pingback: Todd Klindt's SharePoint Admin Blog

  2. Pingback: SharePoint MVP Blogs

  3. Stewart says:

    Awesome article? Do you have any idea how to set the “Enable custom scopes” radio button?

  4. Pingback: JIRA: SharePoint 2010

  5. Paul Grimley says:

    Great post Mark. Incidentily I’ve just spent 2 hours trying to figure out why this wouldnt work for me (kept getting ‘Cannot index into a null array’) and found it was due to PowerGui (I was running as Administrator for UAC). Ran the command from PowerShell and worked fine.

  6. Jason says:

    This will be a huge time saver!! Thanks!

    The setting at the end of the line:
    $web.AllProperties["SRCH_SITE_DROPDOWN_MODE"] = HideScopeDD_Defaultcontextual
    must be quoted, like:
    $web.AllProperties["SRCH_SITE_DROPDOWN_MODE"] = "HideScopeDD_Defaultcontextual"

  7. Pingback: 2010 in review « Mark Rhodes

  8. Pingback: Programmatically set Site’s Search Center | ~似~水~流~年~

  9. gerald says:

    doesn’t work for me. No errors. Just doesn’t hide my scope dropdown.

  10. gerald says:

    Add-PSSnapIn “Microsoft.SharePoint.PowerShell” -EA 0
    $web=Get-SPWeb http://dev.ja.org
    $web.AllProperties[“SRCH_SITE_DROPDOWN_MODE”] = “HideScopeDD_Defaultcontextual”
    $web.update()

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 )

Facebook photo

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

Connecting to %s

%d bloggers like this: