Home > PowerShell, SharePoint 2010, SharePoint Administration > SharePoint 2010: Output Search Query Results Using PowerShell into .csv file

SharePoint 2010: Output Search Query Results Using PowerShell into .csv file

I recently had to perform a massive search query for specific terms (key words) in my SharePoint 2010 environment, and provide a .csv file for all returned results.  The easiest way for me to do this was by utilizing the power of PowerShell.  So instead of having to manually execute separate Search queries within SharePoint Search I executed this script, which outputs the search results in an easy to read formatted .csv file.

#Setup a keyword query object
$site = New-Object Microsoft.SharePoint.SPSite http://portal
$kq = New-Object Microsoft.Office.Server.Query.KeywordQuery $site

#Set some query properties
$kq.ResultTypes = [Microsoft.Office.Server.Search.Query.ResultType]::RelevantResults
$kq.RowlLimit = 10000
$kq.QueryText = “TERM OR KEYWORDS TO QUERY”

#issue the query
$resultTableCollection = $kq.Exectute()

#Get the result Table
$relResultTable = $resultTableCollection.Item([Microsoft.Office.Server.Search.Query.ResultType]::RelevantResults)
$relDataTable = $relResultTable

#Output the results to .csv file
$relDataTable.Rows | select-object Path, Title, Description, Write, HitHighligedSummary | Export-Csv “c:\temp\searchresults.csv” -NoTypeInformation

The .csv file will provide the Path, Title, Description, Date Modified, and Highlighted Summary of the search results.

Hope this helps others that might need to do a similar search against their SP environment.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: