Export search results via PowerShell into CSV

I have a request to export a specific search result set (~430 results) to a .CSV file.  I initially thought PowerShell might be the tool for the job (and still believe this) and found this script here: http://www.bluesphereinc.com/blog/microsoft/sharepoint-search-results-to-csv/

The problem is, I do not get actual data; the script simply dumps a "" result into my file.  Has anyone been able to accomplish something like this using PowerShell or another method?  Thank you in advance for your time.

January 5th, 2015 7:23pm

I tested that script and it works fine. You may want to change the encoding to "utf8" and add the -noType argument.

http://technet.microsoft.com/en-us/library/ee176825.aspx

January 6th, 2015 7:41am

Hi Steve:

The only change in result was that instead of "", I get "".

You say you were able to succeed in exporting your results into a CSV file; how did you specify your search criteria?  I have tried several variations of my query but if yours worked I would be interested to know specifically what you did.

Thank you!

Free Windows Admin Tool Kit Click here and download it now
January 7th, 2015 8:32pm

I only used a keyword term. What is your query supposed to be returning?
January 8th, 2015 7:04am

The query I ran using SharePoint Search Center returned about 430 results. Should I be expecting something different from this script?  I copied it verbatim from the link above:

param (
  [string]$searchString = "$(Read-Host 'Enter a search string:')",
  [Int]$searchRowLimit = "$(Read-Host 'Row Limit (0 for unlimited):')",
  [string]$searchResults = "$(Read-Host 'Path for results(CSV):')"
) 

$snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if ($snapin -eq $null)
{
  Write-Host "Loading SharePoint Powershell Snapin`r`n"
  Add-PSSnapin "Microsoft.SharePoint.Powershell"
}

$proxy = Get-SPEnterpriseSearchServiceApplicationProxy -Identity "Search Service Application"
$query = New-Object Microsoft.office.Server.Search.Query.KeywordQuery $proxy
$query.ResultTypes = [Microsoft.Office.Server.Search.Query.ResultType]::RelevantResults
$query.RowLimit = $searchRowLimit
$query.QueryText = $searchString
$resultTableColl = $query.Execute()
$resultTable = $resultTableColl.Item([Microsoft.Office.Server.Search.Query.ResultType]::RelevantResults)
$resDataTable = $resultTable.Table
$resDataTable.Rows | Select-Object -Property Path,Title | Export-Csv -Path $searchResults -Encoding unicode

I'm really hoping it's just something I'm overlooking; I really need this script to work.
Would my environment have anything to do with it?  I'm using SP13 Server on-prem; the author of the post seemed to think it would work in SP13 though.
  • Edited by E. Owen Thursday, January 08, 2015 5:29 PM
Free Windows Admin Tool Kit Click here and download it now
January 8th, 2015 5:28pm

The query I ran using SharePoint Search Center returned about 430 results. Should I be expecting something different from this script?  I copied it verbatim from the link above:

param (
  [string]$searchString = "$(Read-Host 'Enter a search string:')",
  [Int]$searchRowLimit = "$(Read-Host 'Row Limit (0 for unlimited):')",
  [string]$searchResults = "$(Read-Host 'Path for results(CSV):')"
) 

$snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if ($snapin -eq $null)
{
  Write-Host "Loading SharePoint Powershell Snapin`r`n"
  Add-PSSnapin "Microsoft.SharePoint.Powershell"
}

$proxy = Get-SPEnterpriseSearchServiceApplicationProxy -Identity "Search Service Application"
$query = New-Object Microsoft.office.Server.Search.Query.KeywordQuery $proxy
$query.ResultTypes = [Microsoft.Office.Server.Search.Query.ResultType]::RelevantResults
$query.RowLimit = $searchRowLimit
$query.QueryText = $searchString
$resultTableColl = $query.Execute()
$resultTable = $resultTableColl.Item([Microsoft.Office.Server.Search.Query.ResultType]::RelevantResults)
$resDataTable = $resultTable.Table
$resDataTable.Rows | Select-Object -Property Path,Title | Export-Csv -Path $searchResults -Encoding unicode

I'm really hoping it's just something I'm overlooking; I really need this script to work.
Would my environment have anything to do with it?  I'm using SP13 Server on-prem; the author of the post seemed to think it would work in SP13 though.
  • Edited by E. Owen Thursday, January 08, 2015 5:29 PM
January 8th, 2015 5:28pm

The query I ran using SharePoint Search Center returned about 430 results. Should I be expecting something different from this script?  I copied it verbatim from the link above:

param (
  [string]$searchString = "$(Read-Host 'Enter a search string:')",
  [Int]$searchRowLimit = "$(Read-Host 'Row Limit (0 for unlimited):')",
  [string]$searchResults = "$(Read-Host 'Path for results(CSV):')"
) 

$snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if ($snapin -eq $null)
{
  Write-Host "Loading SharePoint Powershell Snapin`r`n"
  Add-PSSnapin "Microsoft.SharePoint.Powershell"
}

$proxy = Get-SPEnterpriseSearchServiceApplicationProxy -Identity "Search Service Application"
$query = New-Object Microsoft.office.Server.Search.Query.KeywordQuery $proxy
$query.ResultTypes = [Microsoft.Office.Server.Search.Query.ResultType]::RelevantResults
$query.RowLimit = $searchRowLimit
$query.QueryText = $searchString
$resultTableColl = $query.Execute()
$resultTable = $resultTableColl.Item([Microsoft.Office.Server.Search.Query.ResultType]::RelevantResults)
$resDataTable = $resultTable.Table
$resDataTable.Rows | Select-Object -Property Path,Title | Export-Csv -Path $searchResults -Encoding unicode

I'm really hoping it's just something I'm overlooking; I really need this script to work.
Would my environment have anything to do with it?  I'm using SP13 Server on-prem; the author of the post seemed to think it would work in SP13 though.
  • Edited by E. Owen Thursday, January 08, 2015 5:29 PM
Free Windows Admin Tool Kit Click here and download it now
January 8th, 2015 5:28pm

The query I ran using SharePoint Search Center returned about 430 results. Should I be expecting something different from this script?  I copied it verbatim from the link above:

param (
  [string]$searchString = "$(Read-Host 'Enter a search string:')",
  [Int]$searchRowLimit = "$(Read-Host 'Row Limit (0 for unlimited):')",
  [string]$searchResults = "$(Read-Host 'Path for results(CSV):')"
) 

$snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if ($snapin -eq $null)
{
  Write-Host "Loading SharePoint Powershell Snapin`r`n"
  Add-PSSnapin "Microsoft.SharePoint.Powershell"
}

$proxy = Get-SPEnterpriseSearchServiceApplicationProxy -Identity "Search Service Application"
$query = New-Object Microsoft.office.Server.Search.Query.KeywordQuery $proxy
$query.ResultTypes = [Microsoft.Office.Server.Search.Query.ResultType]::RelevantResults
$query.RowLimit = $searchRowLimit
$query.QueryText = $searchString
$resultTableColl = $query.Execute()
$resultTable = $resultTableColl.Item([Microsoft.Office.Server.Search.Query.ResultType]::RelevantResults)
$resDataTable = $resultTable.Table
$resDataTable.Rows | Select-Object -Property Path,Title | Export-Csv -Path $searchResults -Encoding unicode

I'm really hoping it's just something I'm overlooking; I really need this script to work.
Would my environment have anything to do with it?  I'm using SP13 Server on-prem; the author of the post seemed to think it would work in SP13 though.
  • Edited by E. Owen Thursday, January 08, 2015 5:29 PM
January 8th, 2015 8:28pm

The query I ran using SharePoint Search Center returned about 430 results. Should I be expecting something different from this script?  I copied it verbatim from the link above:

param (
  [string]$searchString = "$(Read-Host 'Enter a search string:')",
  [Int]$searchRowLimit = "$(Read-Host 'Row Limit (0 for unlimited):')",
  [string]$searchResults = "$(Read-Host 'Path for results(CSV):')"
) 

$snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if ($snapin -eq $null)
{
  Write-Host "Loading SharePoint Powershell Snapin`r`n"
  Add-PSSnapin "Microsoft.SharePoint.Powershell"
}

$proxy = Get-SPEnterpriseSearchServiceApplicationProxy -Identity "Search Service Application"
$query = New-Object Microsoft.office.Server.Search.Query.KeywordQuery $proxy
$query.ResultTypes = [Microsoft.Office.Server.Search.Query.ResultType]::RelevantResults
$query.RowLimit = $searchRowLimit
$query.QueryText = $searchString
$resultTableColl = $query.Execute()
$resultTable = $resultTableColl.Item([Microsoft.Office.Server.Search.Query.ResultType]::RelevantResults)
$resDataTable = $resultTable.Table
$resDataTable.Rows | Select-Object -Property Path,Title | Export-Csv -Path $searchResults -Encoding unicode

I'm really hoping it's just something I'm overlooking; I really need this script to work.
Would my environment have anything to do with it?  I'm using SP13 Server on-prem; the author of the post seemed to think it would work in SP13 though.
  • Edited by E. Owen Thursday, January 08, 2015 5:29 PM
Free Windows Admin Tool Kit Click here and download it now
January 8th, 2015 8:28pm

Are there other solutions out there? I really would like to get searches via PowerShell working - has anyone used or heard of another solution of searches in PowerShell?  I've also seen this link but I am not proficient in PowerShell enough to get this working either: 

http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2014/01/08/how-to-query-sharepoint-search-with-powershell.aspx

January 15th, 2015 10:58pm

I'm seeing the same behavior when I set the row limit to "0". If I give it a row limit less than 500 and great than 1, I get results. I need the unlimited feature to work. Any ideas why if you set the row limit to zero you get the results E. Owen referenced above? This only happens in 2013, script works fine in 2010.
 
Free Windows Admin Tool Kit Click here and download it now
March 24th, 2015 12:44pm

I'm seeing the same behavior when I set the row limit to "0". If I give it a row limit less than 500 and great than 1, I get results. I need the unlimited feature to work. Any ideas why if you set the row limit to zero you get the results E. Owen referenced above? This only happens in 2013, script works fine in 2010.
 
March 24th, 2015 4:42pm

I'm seeing the same behavior when I set the row limit to "0". If I give it a row limit less than 500 and great than 1, I get results. I need the unlimited feature to work. Any ideas why if you set the row limit to zero you get the results E. Owen referenced above? This only happens in 2013, script works fine in 2010.
 
Free Windows Admin Tool Kit Click here and download it now
March 24th, 2015 4:42pm

I'm seeing the same behavior when I set the row limit to "0". If I give it a row limit less than 500 and great than 1, I get results. I need the unlimited feature to work. Any ideas why if you set the row limit to zero you get the results E. Owen referenced above? This only happens in 2013, script works fine in 2010.
 
March 24th, 2015 4:42pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics