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

[玩转系统] 使用 PowerShell 将 SharePoint 列表项版本历史记录导出到 Excel

作者:精品下载站 日期:2024-12-14 13:48:32 浏览:13 分类:玩电脑

使用 PowerShell 将 SharePoint 列表项版本历史记录导出到 Excel


想要将 SharePoint 列表的版本历史记录提取到 Excel 以进行进一步分析?好吧,我编写了一个PowerShell脚本和C#对象模型代码来在SharePoint文档版本历史报告中生成SharePoint版本历史报告。与此相关的是,我收到了将版本历史记录导出到 Excel 的新要求。

[玩转系统] 使用 PowerShell 将 SharePoint 列表项版本历史记录导出到 Excel

此版本历史报告有助于比较随着时间的推移更改了哪些数据、谁更改了列表数据等。 只需将 WebURL 和 ListName 变量的值替换为您的站点/列表值,然后运行脚本即可从 SharePoint 2013 导出版本历史记录。

将 SharePoint 列表版本历史记录导出到 Excel 的 PowerShell 脚本:

以下是如何从 SharePoint Online 列表导出版本历史记录。


# ******* Variables Section ******************
#Define these variables 
$WebURL="https://sharepoint.crescent.com/sites/Sales/"
$ListName ="Invoice"
$ReportFile = "D:\Invoice_VersionHistory.csv"
# *********************************************

#delete the file if exists
If (Test-Path $ReportFile)
 {
 Remove-Item $ReportFile
 }

#Get the Web and List
$Web = Get-SPWeb $WebURL
$List = $web.Lists.TryGetList($ListName) 

 #Check if list exists
 if($List -ne $null)
 {
  #Get all list items
  $ItemsColl = $List.Items
  
  #Write Report Header
  Add-Content -Path $ReportFile -Value "Item ID, Version Lable, Created by, Created at, Title" 
 
  #Loop through each item
  foreach ($item in $ItemsColl) 
  {
      #Iterate each version
      ForEach($version in $item.Versions)
      {
         #Get the version content
         $VersionData = "$($item.id), $($version.VersionLabel), $($version.CreatedBy.User.DisplayName), $($version.Created), $($version['Title'])"
         #Write to report
         Add-Content -Path $ReportFile -Value $VersionData
       }
    }
 }
Write-Host "Version history has been exported successfully!"

请注意,在第 25 行和第 36 行中,我仅添加了列表中的“标题”字段。您可能需要根据您的要求添加其他字段。运行脚本时,所有列表项版本都将导出到 Excel(CSV 格式)。

要导出 SharePoint 文档版本历史记录,请参阅:使用 PowerShell 提取并下载所有文档版本

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

取消回复欢迎 发表评论:

关灯