当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] PowerShell 使用关键字查询搜索 SharePoint 并将结果导出到 CSV

作者:精品下载站 日期:2024-12-14 14:52:54 浏览:15 分类:玩电脑

PowerShell 使用关键字查询搜索 SharePoint 并将结果导出到 CSV


要求: 搜索 SharePoint 网站并使用 PowerShell 将搜索结果导出到 CSV 文件。

PowerShell 将 SharePoint 搜索结果导出到 CSV

有时,将搜索结果导出为熟悉的格式(例如 Excel)以便进一步分析和处理会很有帮助。在这篇博文中,我们将向您展示如何使用 PowerShell 在 SharePoint 中搜索信息并将搜索结果导出到 CSV 文件。这使得分析和报告您找到的数据变得容易。

以下是用于搜索 SharePoint Online 网站集中的所有文档并将搜索结果导出为 CSV 的 PowerShell:


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!"

执行此脚本后,搜索结果将导出到 Excel 文件,使您能够以熟悉的电子表格格式对数据进行排序、筛选和分析。以下是 CSV 搜索结果示例:

[玩转系统] PowerShell 使用关键字查询搜索 SharePoint 并将结果导出到 CSV

通过遵循本文中提供的脚本,您可以快速轻松地将搜索结果导出到 CSV 文件。无论您需要跟踪指标、分析趋势还是只是记录搜索结果,导出到 Excel 都可以帮助您充分利用 SharePoint 搜索体验。将搜索结果导出到 Excel 后,您可以使用 Excel 强大的筛选和排序功能快速深入查找所需的信息,而无需在 SharePoint 页面之间来回导航。

以下是如何使用关键字查询搜索 SharePoint Online:PowerShell 使用关键字查询搜索 SharePoint Online 网站

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯