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://addressBy 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
$web.AllProperties[“SRCH_TRAGET_RESULTS_PAGE”] =”/_layouts/OSSSearchResults.aspx”
$web.update()
Pingback: Todd Klindt's SharePoint Admin Blog
Pingback: SharePoint MVP Blogs
Awesome article? Do you have any idea how to set the “Enable custom scopes” radio button?
Awesome article! Do you have any idea how to set the “Enable custom scopes” radio button?
Never mind. I had my script wrong and the update wasn’t committing. Again, great article!
Pingback: JIRA: SharePoint 2010
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.
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"
Pingback: 2010 in review « Mark Rhodes
Pingback: Programmatically set Site’s Search Center | ~似~水~流~年~
doesn’t work for me. No errors. Just doesn’t hide my scope dropdown.
Add-PSSnapIn “Microsoft.SharePoint.PowerShell” -EA 0
$web=Get-SPWeb http://dev.ja.org
$web.AllProperties[“SRCH_SITE_DROPDOWN_MODE”] = “HideScopeDD_Defaultcontextual”
$web.update()