Sharepoint PowerShell query search service

fredericdietrich By On 29/09/2018

In Powershell

SharePoint PowerShell query search service

param([string]$siteCollectionUrl="http://mySiteUrl" ,
$keyword="ContentTypeId:0x010100020D149374FFC4DF792F30EFC030C9D01* ",
$rowLimit=500,
$SelectProperties="Title,SPWebUrl,Path"
)
 
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
$site = Get-SPSite $siteCollectionUrl
$keywordQuery = New-Object Microsoft.Office.Server.Search.Query.KeywordQuery($site);
 
#set request
$keywordQuery.QueryText = $keyword
 
#set managed properties to retreive
foreach($mnp in $SelectProperties.Split(","))
{
$keywordQuery.SelectProperties.Add($mnp.Trim());
}
$keywordQuery.RowLimit = $rowLimit
 
$searchExec = New-Object Microsoft.Office.Server.Search.Query.SearchExecutor
$searchResults = $searchExec.ExecuteQuery($keywordQuery)
 
#display results
$table = $searchResults.Table
$table | Select Title, SPWebUrl, Path
 
$site.Dispose()
 

powershell Sharepoint Search

  • No ratings yet - be the first to rate this.