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