4

I am attempting to use PowerShell to change the the seach scope which is by default "All Sites" to "All Content". I have tried

 $sitecontext = get-SpServiceContext $siteUrl
 $mgr = new-object Microsoft.Office.Server.Search.Administration.RemoteScopes($sitecontext)
 $scope = $mgr.GetSharedScope("All Sites")
 $scope.name = "All Content"
 $scope.update()
 $mgr.update() //unnessacery?
 $mgr.StartCompilation()

When i go to the site > site settings > search scopes it shows that the scope has been renamed but value actually displayed in the search dropdown remains unchanged.

Search dropdown mode = "Show, do not include contextual scopes, and default to 's' url parameter"

What am i missing?

  • 1
    there is a typo, see undefined variable $siteconext , is it so that the specified code is executed without any error? – Vadim Gremyachev Jan 4 '14 at 16:26
  • there was no typo when I had actually ran it in PS. It executed without any errors & I can the correct results in the Site Settings when using the browser but the toolbar dropdown still remains "All Sites" – user13186 Jan 6 '14 at 19:23
0

Unfortunately, this is not possible. The All Sites scope is hard coded with an ID of "1". In the search box code, when determining the display name, it looks for that value and then looks up a hard coded resource string (not externalized in a RESX file, but compiled in the search assemblies):

internal static string GetScopeDisplayName(ScopeInformation scope)
{
    if (scope == null)
    {
        return string.Empty;
    }
    if (scope.ID == 0)
    {
        return GetLocResourceString(LocStringId.PeopleSearch_Scope);
    }
    if (scope.ID == 1)
    {
        return GetLocResourceString(LocStringId.Search_DatabaseManage_AllSites);
    }
    return scope.Name;
}

Furthermore, there isn't anyway to delete or hide that scope. Meaning, you could copy it to create your own scope, but there is nothing to prevent this one from still being displayed.

Only alternatives I think are to 1) create your own search box control and replace the ones rendered on the pages (this would let you do whatever you want when it comes to scopes, etc.), or 2) do some ugly JavaScript to remove the All Sites scope from the drop down list once it renders.

| improve this answer | |
  • BTW, the code I pasted into the answer is what the search box is using to get the scope name for display. Retrieved using .NET Reflector. – John Chapman May 23 '14 at 18:44
  • I had found we were using an extended SearchBoxEx web control which added dropdown items. I then added and override to the OnPreRender event where I was able to change the text of them item. – user13186 May 27 '14 at 15:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.