2015-11-04 86 views
0

我正在通過PowerShell腳本設置SharePoint 2013搜索中心。我可以將內容源,爬網規則等等,所有這似乎工作很好,但我不能創建一個「ResultSource」:'New-SPEnterpriseSearchResultSource'未被識別爲cmdlet的名稱

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 

有沒有人曾經遇到過這個?

回答

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

+0

你好 - 感謝您的答覆,但它似乎沒有有所作爲。它加載得很好(版本v4.0.30319?),但仍然不能識別術語'New-SPEnterpriseSearchResultSource'。 –

相關問題