SharePoint Online: Export List Version History to Excel using PowerShell

Requirement: Export all versions of SharePoint Online List Items to CSV (Excel) file.
sharepoint online export list version history to excel using powershell

PowerShell to Extract and Export List Item's Version History to CSV File:
This article assumes you have an existing SharePoint Online list with columns given below. You may have to create and change columns according to your requirement.
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

Function Export-VersionHistory()
        [Parameter(Mandatory=$true)] [string] $SiteURL,
        [Parameter(Mandatory=$true)] [string] $ListName,
        [Parameter(Mandatory=$true)] [string] $CSVFile
    Try {

        #Delete the Output report file if exists
        if (Test-Path $CSVFile) { Remove-Item $CSVFile }

        #Get Credentials to connect
        $Cred= Get-Credential
        $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Credentials
        #Get the List
        $List = $Ctx.Web.Lists.GetByTitle($ListName)
        #Get all items
        $Query = [Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery()
        $ListItems = $List.GetItems($Query)

        #Array to hold result
        $VersionHistoryData = @()

        #Iterate throgh each item
        Foreach ($Item in $ListItems)
            write-host "Processing Item:" $ -f Yellow
            #Get all versions of the list item
            $Versions = $Item.versions

            If($Versions.count -gt 0)
                #Iterate each version
                Foreach($Version in $Versions)
                    #Get the Creator object of the version
                    $CreatedBy =  $Version.createdby

                    #Send Data to object array
                    $VersionHistoryData += New-Object PSObject -Property @{
                    'Item ID' = $Item.ID
                    'Title' =  $Version.FieldValues["Title"]
                    'Version Label' = $Version.VersionLabel 
                    'Version ID' = ($Version.VersionId/512)
                    'Created On' = (Get-Date ($Version.Created) -Format "yyyy-MM-dd/HH:mm:ss")
                    'Created By' = $CreatedBy.Email
        #Export the data to CSV
        $VersionHistoryData | Export-Csv $CSVFile -Append -NoTypeInformation

        write-host -f Green "Version History Exported Successfully to:" $CSVFile
    Catch {
        write-host -f Red "Error Exporting version History to CSV!" $_.Exception.Message

#Set parameter values

#Call the function to generate version History Report
Export-VersionHistory -SiteURL $SiteURL -ListName $ListName -CSVFile $CSVFile
Important: This script works ONLY on CSOM version 16.1.6906.1200 or Later! Download the latest version of CSOM SDK from

This script produces a CSV file with version data such as:
  • Version Label,
  • Version ID
  • When the version was created
  • Who created the version
  • Title field value of the version (You can add any additional field too!)
For SharePoint On-Premises, use this script: How to Export SharePoint Version History to CSV using PowerShell?

PnP PowerShell to Extract Version History of All Items in a List
Let's export all previous versions of items from a list to a CSV file using PnP PowerShell.
#Set Variables
$SiteURL = ""
$ListName = "Announcements"
$CSVPath = "C:\Temp\VersionHistoryRpt.csv"
#Connect to SharePoint Online site
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Get All Fields from List
$ListFields = Get-PnPField -List $ListName | Where {!$_.Hidden}
$VersionHistoryData = @()

#Get All List Items - Exclude Folders
Get-PnPListItem -List $ListName -PageSize 500 | Where {$_.FileSystemObjectType -ne "Folder"} | ForEach-Object {
    Write-host "Getting Versioning Data of Item:"$_.ID
    $Versions = Get-PnPProperty -ClientObject $_ -Property Versions
    ForEach($Version in $Versions)
        $VersionHistory =  New-Object PSObject
        $VersionHistory | Add-Member -MemberType NoteProperty -Name "Version ID" -Value ($Version.VersionId/512)
        $VersionHistory | Add-Member -MemberType NoteProperty -Name "Version Label" -Value $Version.VersionLabel
        $VersionHistory | Add-Member -MemberType NoteProperty -Name "Created On" -Value (Get-Date ($Version.Created) -Format "yyyy-MM-dd/HH:mm:ss")

        #Get Value of all other Fields
        $ListFields | ForEach-Object {
            #Get the value of Person or Lookup fields
            $FieldType = $_.GetType().Name
            If (($FieldType -eq "FieldLookup") -or ($FieldType -eq "FieldUser"))
                $FieldValue = $Version[$_.InternalName].LookupValue
                $FieldValue = $Version[$_.InternalName]
            #Append Version data
            $VersionHistory | Add-Member -MemberType NoteProperty -Name $_.InternalName -Value $FieldValue
$VersionHistoryData | Export-Csv $CSVPath -NoTypeInformation


  1. Hi,

    Thanks for this code a life saver. However, there is an error in your code. The $SiteURL = "..." is wrong you have a html hyperlink ref in there when in your case it should be $SiteURL = "".

    This caught me out for a few hours lol

    1. Hi There, $SiteURL="" is what I've posted. Let me know if this is not what you are getting!

  2. Thanks Salaudeen for the detailed PS script. When I run the Powershell, I am getting ,Cannot find an overload for "Load" and the argument count: "1"'

    1. Make sure you have the latest client SDK installed in your machine as per the link given in the post. Also, try running this in PowerShell ISE.

    2. Yes, I have installed the latest client SDK (32 Bit). I wanted this PS to run as a scheduled task and I am not sure how I can achieve that. My environment is O365.

  3. Hi Salundeen,

    thanks for this great site. I'm in my first steps with PowerShell and have a question. What do I have to change in the script, so it can run on SharePoint 2010?


  4. Do you think this script work for SharePoint 2010/13/2016 on-premise?

  5. Thank you, You are good among men!

  6. Thanks, your article helped me to solve my user request!

  7. Hi Salundeen,
    Mi name is Guille (from Spain).
    thank you for sharing your code and wisdom with all of us.

    I have a problem executing your code. Before I start, tell you what I've done or I am doing:
    - I have installed the latest version of the SDK (64 bits)
    - My SharePoint site is $SiteURL="".
    In this collection I created a list of tasks called MyTasks (whose URL is :
    ). Then my variable $ListName="MyTasks"
    - I am using PowerShell ISE (as administrator). I copied your code into a .ps1 file and run it from PowerShell ISE itself.

    Well, when I execute an error appears (it is located in the first ExecuteQuery) that says:
    Error Exporting version History to CSV! Exception when calling "ExecuteQuery" with the arguments "0": "The 'MyTasks' list does not exist on the site with the URL address 'ht

    I can't see why this is happening.
    Can you help me?

  8. Script is working fine, but how to fetch last updated comments on list item ? is there any way ?

  9. How can I limit the list by a date range? I am getting this error:
    Error Exporting version History to CSV! Exception calling "ExecuteQuery" with "0" argument(s): "The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator."

    1. Well, on large lists you must get items in batches to mitigate list view threshold issue. Here how: SharePoint Online: How to Get All List Items from Large Lists ( >5000 Items)

  10. Hi there! am getting error: Add-Type : Cannot bind parameter 'Path' to the target. Exception setting "Path": "Cannot find path... Any ideas on why? Thanks

    1. You need to install either CSOM Assemblies for SharePoint Online or SharePoint Online PowerShell Module!
      Run: Install-Module -Name Microsoft.Online.SharePoint.PowerShell
      Or download and install SharePoint Online Client Components SDK from

  11. Hi Salaudeen. A fantastic script here. Just wondering, what would need to be added to include a particulars columns data from each version into the output csv?

    1. $Version["FieldInternalName"] will get you the particular column's value for the version!


Please Login and comment to get your questions answered!

Powered by Blogger.