Powershell - push search scopes into Site Collection Display Groups RRS feed

  • Question

  • I have created a script that is annoying me, it seems to error on some site collections and not others which I thought was due to permissions but this seems not to be the case. It will add the scopes in multiple times to some site collections, even though I'm checking to see if they are already present. 

    The script iterates through all the site collections in a web application and updates each Search scope display group called "Search Dropdown" which is the default. 

    #name of the scope display group 
    $DisplayGroupName = "Search Dropdown"
    #scope names as defined in Search Service Application
    $scope1 = "Intranet" 

    $SiteURL = "https://webapplicationurl.contoso.com"
    $rootSite = New-Object Microsoft.SharePoint.SPSite($siteURL)
    $webApp = $rootSite.WebApplication

    foreach($site in $webApp.Sites)
      $URL = $site.URL
      $searchContext = [Microsoft.Office.Server.Search.Administration.SearchContext]::GetContext($Site)
      $scopes = new-Object Microsoft.Office.Server.Search.Administration.Scopes($searchContext)
      $displayGroup = $scopes.GetDisplayGroup($Url, $DisplayGroupName)

      Write-Host "$scope1 is not currently in display group for $site" -foregroundcolor Yellow
      Write-Host "Now adding $scope1 to display group for $site" -foregroundcolor Yellow
    else {Write-host "$scope1 is already in that display group for $site" -foregroundcolor Yellow}

    Any ideas?

    Paul Griffiths - MCTS, MCITP SharePoint 2010

    Thursday, March 29, 2012 6:56 PM




    From your PowerShell script, it seems that you don’t define $site variable. I suggest you refer to the following article to re-write the script, then check the result.


    $site=get-spsite $siteURL


    $displayDescription="Custom Display Group"

    $owningSiteURL=New-Object System.Uri($site.URL)






    $scopes=New-Object Microsoft.Office.Server.Search.Administration.Scopes($searchContext)









    Rock Wang

    Rock Wang TechNet Community Support

    Tuesday, April 3, 2012 6:51 AM