Add Custom Scope to SharePoint Search Dropdown using PowerShell

Requirement: We’ve created a custom search scope “Search All Documents” in SharePoint Central Admin and would like to include it in search scope drop downs of few site collections.

SharePoint: Add search scope to drop-down
Well, it’s a few clicks job to include custom search scopes to search drop down in SharePoint. Here is how:

  1. Go to Site Actions >> Site Settings
  2. Click on “Search Scopes” link under Site collection administration Add Custom Scope to SharePoint Search Dropdown using PowerShell
  3. Click on the “Display Groups” link and choose “Search Dropdown”
    Edit Search Dropdown Scopes
  4. From here, we can include/exclude any scopes to search dropdown by simply selecting/deselecting check-boxes.Edit Search Scopes Dropdown

Add a custom scope to SharePoint Search Scope Dropdowns using PowerShell

While it’s not tedious to customize search scope dropdowns by following the above steps for a few sites, We had to do it for all site collections under a particular managed path. (around 50!). Here is the PowerShell script to add custom search scopes to the SharePoint search dropdown:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Set these three variables accordingly
$SiteURL  = "https://sharepoint.crescent.com/sites/operations/"
$CustomSearchScopeName = "Search All Documents"
$DisplayGroupName = "Search Dropdown"

#Get the Site Object
$Site= Get-SPSite $siteURL

#Initialize 
$SearchContext= [Microsoft.Office.Server.Search.Administration.SearchContext]::GetContext($site)
$Scopes= New-Object Microsoft.Office.Server.Search.Administration.Scopes($searchContext)

#Get the Display Group 
$SearchDropdownDisplayGroup =  $scopes.GetDisplayGroupsForSite($SiteURL) | Select-Object -First 1
#Get the custom scope
$CustomSearchScope = $Scopes.GetSharedScope($CustomSearchScopeName)

#Add custom scope to Display group
$SearchDropdownDisplayGroup.Add($CustomSearchScope)
$SearchDropdownDisplayGroup.Update()
 

See the result in action:Include Custom Scope to SharePoint Search Dropdown PowerShell

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

Leave a Reply

Your email address will not be published. Required fields are marked *