When run, this code returns an error on the last line "Error Calling GetDisplayGroup with 2 arguments, Specified cast is not valid".
$site=get-spsite http://xxx/sites/xxx
$displayName="Search Dropdown"
$owningSiteURL=New-Object System.Uri($site.URL)
$displayInAdminUI=$true
$addScope="Forms Library"
$searchContext=[Microsoft.Office.Server.Search.Administration.SearchContext]::GetContext($site)
$scopes=New-Object Microsoft.Office.Server.Search.Administration.Scopes($searchContext)
$displayGroup=$scopes.GetDisplayGroup($owningSiteURL,$displayName)
The reference documents on MSDN show 2 arguments to be passed, a System.Uri and a string. Near as I can tell this is what is happening. Anyone have any idea? I suspect an issue to get bumped to Microsoft but not sure...
EDIT TO ADD: I should also add that when we access the site (via a browser, not even a PowerShell WebClient visit will do the trick) the problem resolves, nice that it can be fixed by this, but I'm trying to set a default search group for 500+ sites, visiting each one by browser after running to that far in the script is not a practical option.