“New-SPEnterpriseSearchResultSource”未被识别为cmdlet的名称

时间:2015-11-04 18:13:42

标签: powershell sharepoint-2013

我正在通过PowerShell脚本设置SharePoint 2013搜索中心。我可以使用内容来源,抓取规则等等所有这些似乎都可以正常工作,但我无法创建“ResultSource”:

PS > New-SPEnterpriseSearchResultSource
New-SPEnterpriseSearchResultSource : The term 'New-SPEnterpriseSearchResultSource' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ New-SPEnterpriseSearchResultSource
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (New-SPEnterpriseSearchResultSource:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

这很奇怪。看起来列表New-SPEnterpriseSearchResultSource on Technet底部的那些cmdlet不存在:我有“SearchResultItemType(s)”的功能,但不是“SearchResultSrouce(s)”。

PS > Get-Command -Module *Sharepoint* -name *SearchResult*

CommandType     Name                                               ModuleName
-----------     ----                                               ----------
Cmdlet          Get-SPEnterpriseSearchResultItemType               Microsoft.SharePoint.PowerShell
Cmdlet          New-SPEnterpriseSearchResultItemType               Microsoft.SharePoint.PowerShell
Cmdlet          Remove-SPEnterpriseSearchResultItemType            Microsoft.SharePoint.PowerShell
Cmdlet          Set-SPEnterpriseSearchResultItemType               Microsoft.SharePoint.PowerShell

有没有人曾经遇到过这个?

1 个答案:

答案 0 :(得分:0)

您必须将程序集加载到搜索

 [void] [Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.Search")

基本代码如下

$publishingSite = Get-SPSite "http://c4968397007:1000/"
$sspApp = Get-SPEnterpriseSearchServiceApplication;

# load Search assembly

[void] [Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.Search")

# create manager instances

$fedManager = New-Object Microsoft.Office.Server.Search.Administration.Query.FederationManager($sspApp)
$searchOwner = New-Object Microsoft.Office.Server.Search.Administration.SearchObjectOwner([Microsoft.Office.Server.Search.Administration.SearchObjectLevel]::Ssa, $publishingSite.RootWeb)

# define query

$query = '{searchTerms?}'
$queryProperties = New-Object Microsoft.Office.Server.Search.Query.Rules.QueryTransformProperties
# define custom sorting
$sortCollection = New-Object Microsoft.Office.Server.Search.Query.SortCollection
$sortCollection.Add("Title", [Microsoft.Office.Server.Search.Query.SortDirection]::Ascending)
$queryProperties["SortList"] = [Microsoft.Office.Server.Search.Query.SortCollection]$sortCollection

# create result source
$resultSource = $fedManager.CreateSource($searchOwner)
$resultSource.Name = 'Result Source Through PowerShell'
$resultSource.ProviderId = $fedManager.ListProviders()['Local SharePoint Provider'].Id
$resultSource.CreateQueryTransform($queryProperties, $query)

$resultSource.Commit()

您可以看到更多此link