Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
$searchScopeDisplayGroup.Clear()
#$searchScopeDisplayGroupScopes are xml nodes from a config file 
$searchScopeDisplayGroupScopes | ForEach-Object {
$displayGroupScopeCurrent = $_
$searchScope = $scopesManager.AllScopes | Where { $_.Name -eq $displayGroupScopeCurrent.name }
$searchScopeDisplayGroup.Add($searchScope)
}
$searchScopeDisplayGroup.Update()

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

1 Answer 1

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

 
discard

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.