2

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

1 Answer 1

1

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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