Set Site Collection Search Settings by PowerShell
September 14, 2010 12 Comments
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|
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