SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to edit the Searchbox Scopes dropdown ScopeDisplayGroup using Powershell using the following code (partly backwards engineered from the scope edit layouts page codebehinds):

$ddScopeDisplayGroupName = [Microsoft.SharePoint.Utilities.SPUtility]::GetLocalizedString("`$Resources:ScopeDisplayGroup_SearchDropdown_Name", "spscore", $site.RootWeb.Locale.LCID)

$serviceContext = Get-SPServiceContext -Site "http://somesite"
$scopesManager = New-Object Microsoft.Office.Server.Search.Administration.RemoteScopes($serviceContext)
$searchScopeDisplayGroup = $scopesManager.AllDisplayGroups | Where { $_.Name -eq $ddScopeDisplayGroupName } | Select-Object -First 1
#$searchScopeDisplayGroupScopes are xml nodes from a config file 
$searchScopeDisplayGroupScopes | ForEach-Object {
$displayGroupScopeCurrent = $_
$searchScope = $scopesManager.AllScopes | Where { $_.Name -eq $ }

When I try to manipulate the $searchScopeDisplayGroup variable (at for instance $searchScopeDisplayGroup.Clear() ) I get an unauthorized exception. ILSpy tells me this methods checks to see if I am a siteadmin, but I am (farm admin even).

Is this a bug in PoSH? Creating a (shared) display group works fine, it is not until I go into an actual SPSite that I get a sec. exception. Maybe this has to do with for instance not having a HttpContext or something?

ANy thoughts appreciated

share|improve this question
up vote 1 down vote accepted

A little more digging in ILSpy brought me to the following:

$scopesManager = New-Object Microsoft.Office.Server.Search.Administration.RemoteScopes($serviceContext)
$searchScopeDisplayGroup = $scopesManager.GetDisplayGroup($webAppUri, $ddScopeDisplayGroupName)

No more unauthorized error!

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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