I wrote a PowerShell script and C# object model codes to generate SharePoint version history report in SharePoint document version history report, related to that, got a new requirement to export version history to excel.

export sharepoint list version history to excel using powershell

This version history report helps to compare what data is changed, who changed the list data, etc over time.  just replace the values of WebURL, ListName variables with your Site/List values and run the script to export version history SharePoint 2013.

PowerShell script to Export SharePoint List version history to excel:

# ******* Variables Section ******************
#Define these variables 
$WebURL="http://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!"

Please note, in line numbers 25 and 36, I’ve added only “Title” field from the list. You may want to add additional fields as per your requirement. On running the script, all list item versions will be exported to Excel (CSV format).

To export SharePoint document version history, Refer: Extract and Download All Document Versions using PowerShell

Source link