使用 PowerShell 将自定义范围添加到 SharePoint 搜索下拉列表
要求:我们已在 SharePoint Central Admin 中创建了自定义搜索范围“搜索所有文档”,并希望将其包含在少数网站集的搜索范围下拉列表中。
SharePoint:将搜索范围添加到下拉列表
嗯,只需点击几下鼠标即可将自定义搜索范围添加到 SharePoint 中的搜索下拉列表中。具体方法如下:
使用 PowerShell 将自定义范围添加到 SharePoint 搜索范围下拉列表
虽然通过对一些网站执行上述步骤来自定义搜索范围下拉列表并不乏味,但我们必须对特定托管路径下的所有网站集执行此操作。 (大约 50 个!)。以下是用于将自定义搜索范围添加到 SharePoint 搜索下拉列表的 PowerShell 脚本:
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()
查看实际结果:



