none
Powershell - push search scopes into Site Collection Display Groups

    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)

    if(!$displayGroup.Contains($scopes.GetSharedScope($scope1)))
      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
      $displayGroup.Add($scopes.GetSharedScope($scope1))
      $displayGroup.Update()
    }
    $site.dispose()
    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

Answers

  •  

    Hi,

    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.

    $siteURL="http://servername:1111/"

    $site=get-spsite $siteURL

    $displayName="CustomDisplayGroup"

    $displayDescription="Custom Display Group"

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

    $displayInAdminUI=$true

    $scope1="CustomSiteScope"

    $scope2="CustomScope"

    $defaultScope=$scope2

    $searchContext=[Microsoft.Office.Server.Search.Administration.SearchContext]::GetContext($site)

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

    $displayGroupColl=$scopes.AllDisplayGroups

    $displayGroup=$displayGroupCOll.Create($displayName,$displayDescription,$owningSiteURL,$displayInAdminUI)

    $displayGroup.Add($scopes.GetSharedScope($scope1))

    $displayGroup.Add($scopes.GetSharedScope($scope2))

    $displayGroup.Default=$scopes.GetSharedScope($defaultScope)

    $displayGroup.Update()

    http://www.c-sharpcorner.com/uploadfile/anavijai/using-powershell-create-modify-and-delete-search-scope-display-group-in-sharepoint-2010/

    Thanks,

    Rock Wang


    Rock Wang TechNet Community Support

    Tuesday, April 3, 2012 6:51 AM