Requirement: Search a SharePoint site and export the search results to a CSV file using PowerShell.
PowerShell to Export SharePoint Search Results to CSV
At times, it can be helpful to export the search results to a familiar format like Excel for further analysis and processing. In this blog post, we will show you how to use PowerShell to search for information in SharePoint and export the search results to a CSV file. This makes it easy to analyze and report on the data that you find.
Here is the PowerShell to search all documents in a SharePoint Online site collection and export search results to CSV:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue #Set Parameters $SiteURL = "https://intranet.crescent.com/" $CSVFile = "C:\Temp\SearchResults.csv" #Get the site collection $Site = Get-SPSite $SiteURL #Frame Query to search: Get all documents sorted by Last modified $keywordQuery = New-Object Microsoft.Office.Server.Search.Query.KeywordQuery($Site) $SearchQuery = "site:https://intranet.crescent.com ContentType:document NOT FileExtension:aspx" $keywordQuery.QueryText = $SearchQuery $keywordQuery.SortList.Add("LastModifiedTime","Asc") #Execute Search $SearchExecutor = New-Object Microsoft.Office.Server.Search.Query.SearchExecutor $searchResults = $SearchExecutor.ExecuteQuery($keywordQuery) #Get Search Results $Table = $SearchResults.Table $Table | select Title, Path, Author, LastModifiedTime #Export Search results to Excel $Table | Export-Csv $CSVFile -NoTypeInformation Write-Host -f Green "Search Results Exported to CSV File!"
Once you have executed this script, the search results will be exported to an Excel file, allowing you to sort, filter, and analyze the data in a familiar spreadsheet format. Here is the sample search result CSV:
By following the scripts provided in this article, you can quickly and easily export your search results to a CSV file. Whether you need to track metrics, analyze trends, or just keep a record of your search results, exporting to Excel can help you to get the most out of your SharePoint search experience. Once you have exported your search results to Excel, you can use the powerful filtering and sorting capabilities of Excel to quickly drill down to the information you need, without having to navigate back and forth between SharePoint pages.
Here is how to search SharePoint Online using Keyword query: PowerShell to Search SharePoint Online Site using Keyword Query