当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 使用 PowerShell 将自定义范围添加到 SharePoint 搜索下拉列表

作者:精品下载站 日期:2024-12-14 13:44:33 浏览:14 分类:玩电脑

使用 PowerShell 将自定义范围添加到 SharePoint 搜索下拉列表


要求:我们已在 SharePoint Central Admin 中创建了自定义搜索范围“搜索所有文档”,并希望将其包含在少数网站集的搜索范围下拉列表中。

SharePoint:将搜索范围添加到下拉列表
嗯,只需点击几下鼠标即可将自定义搜索范围添加到 SharePoint 中的搜索下拉列表中。具体方法如下:

  1. 转到网站操作>>网站设置
  2. 单击网站集管理下的“搜索范围”链接

    [玩转系统] 使用 PowerShell 将自定义范围添加到 SharePoint 搜索下拉列表

  3. 单击“显示组”链接并选择“搜索下拉菜单”

    [玩转系统] 使用 PowerShell 将自定义范围添加到 SharePoint 搜索下拉列表

  4. 从这里,我们可以通过简单地选择/取消选择复选框来包含/排除搜索下拉列表的任何范围。

    [玩转系统] 使用 PowerShell 将自定义范围添加到 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()
 

查看实际结果:

[玩转系统] 使用 PowerShell 将自定义范围添加到 SharePoint 搜索下拉列表

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯