Export SharePoint Version History to Excel Using PowerShell

Export SharePoint Version History to Excel Using PowerShell

In this post, we’re gonna introduce a new PowerShell Script “SPDocVersion-Exporter” that would help you to Export SharePoint Version History Details with Comments for all documents in a specific SharePoint Document Library using PowerShell.

Export SharePoint Version History to Excel using PowerShell SPDocVersion-Exporter
SPDocVersion-Exporter

Export SharePoint Version History to Excel

Consider you have a SharePoint Document Library that holds several documents

get sharepoint document versions powershell

In this SharePoint document Library, the Document Version History and Checked-Out settings has been enabled as shown below:

sharepoint list version history export to excel

Now, if you need to show the Version History details for specific document, so you can easily select this document and from the File tab, click on Version History.

export all Versions with comments in SharePoint Document Library using PowerShell

Alternatively, you can also explore the SharePoint Document Versions History as below:

Export SharePoint Version History to Excel Using PowerShell

Regardless, the method that you will use to show the SharePoint Document Versions History, consider, you have several documents and you need to show and export the Versions History for all documents in one view!

In this case, I think it will be a silly task to manually show the version details history for each document one by one! Also, there is no Export to Excel option to export the version history details for each document as shown below!

Export SharePoint Version History to Excel Using PowerShell

So that, our main goal in this post is to overcome such SharePoint limitations by introducing a well-written and tested PowerShell script “SPDocVersion-Exporter” that would help you to export all SharePoint document versions history details for each document in a SharePoint document library with just a push of a button.


What’s SPDocVersion-Exporter?

The SPDocVersion-Exporter is a PowerShell Script to export the document version history details for all documents in a specific SharePoint Document Library to Excel\CSV file.

Export SharePoint document Version History to Excel PowerShell
Export SharePoint Version History

Note: This script was previously published on TechNet Gallery in 2017 and was improved upon and published on PowerShell Gallery in 2021.

Supported SharePoint Versions

The SPDocVersion-Exporter script was tested on multiple farms that have the following SharePoint versions installed:

  • SharePoint 2019.
  • SharePoint 2016.
  • SharePoint 2013.

Script Features

Below, we’re gonna list the main features and capabilities of SPDocVersion-Exporter PowerShell Script:

Informative

  1. Get all document details like
    • Document ID,
    • Document Name,
    • Document URL,
    • Total number of versions,
    • Created By,
    • Created Date,
    • Modified By,
    • Modified Date,
    • File Size.
  2. Show all version history details with comments for each document like
    • Version ID,
    • Version Title,
    • Modified By,
    • Modified Date,
    • Version Size,
    • Check-In Comment.
  3. Show the document details first then list all related version details.
export sharepoint version details powershell
  1. Show the detailed steps for each document.
export list version details in sharepoint powershell
  1. Show a summary of the export operation.
    • Get the total number of all documents in SharePoint Document Library.
    • Get the count of all versions in SharePoint Document Library.
Export SharePoint Version History to Excel using PowerShell
Export SharePoint Version History

Validation and Verification

  1. Perform validation and verification for the SharePoint Site URL, the Document Library Name, and the Exported file Path.
check if SharePoint URL found powershell
  1. It also checks if the version settings for a document library have been enabled or not before proceed.
Check if the version settings enabled for a document library in SharePoint using PowerShell

If the versioning setting is not enabled, the script will automatically open the Document Library Versioning Settings to enable it.

sharepoint list version history export to excel

Versioning

  1. Build an independent folder for each document library.
  2. Organize each result in a particular file classified by the current date and time.
  3. Don’t overwrite old files.
powershell export sharepoint list library

Flexible

The SPDocVersion-Exporter provides you two options to export SharePoint Version History :

  1. Export the version history for ALL documents.
  2. Export the version history for a particular document.
export version history for a SharePoint document powershell

Easy to use

  1. No additional configuration on your side, you only need to install SPDocVersion-Exporter script from PowerShell Gallery,
Export SharePoint Version History to Excel using PowerShell SPDocVersion-Exporter
SPDocVersion-Exporter
  1. Provides only two parameters (SharePoint Site URL, Document Library Name).
  2. Type “All” to export SharePoint Version History for all documents or paste the “document URL” to export a specific document version.
  3. Once the script is run successfully, the exported file will be opened automatically to show the result.
Export SharePoint document Version History to Excel PowerShell
Export SharePoint Version History

How to use SPDocVersion-Exporter?

To export SharePoint Document Library Version Details to Excel using “SPDocVersion-Exporter”, you should do the following:

  1. Open the Windows PowerShell As administrator.
run Windows PowerShell as Administrator
  1. Type the below cmdlet to install the “SPDocVersion-Exporter” script.
Install-Script -Name SPDocVersion-Exporter
install script from PowerShell Gallery

Note: Install-Script runs on PowerShell 5.0 or later releases, for more details, Please check The term ‘Install-Module’ is not recognized

If you don’t have an internet connection on your server, you can manually download the .nupkg file, and install it as mentioned in the Manual Package Download

If you already installed the “SPDocVersion-Exporter” script, and you would like to get the latest version, so you will need to reinstall the script again with the -force

Ex: Install-Script -Name SPDocVersion-Exporter -force

  1. After installing the script, type the below cmdlet to run it.
SPDocVersion-Exporter
  1. The script will ask you to provide the below parameter values:
    • siteURL: SharePoint Site that holds the document library.
    • DocLibName: the document library display name (without quotation)
PowerShell Export SharePoint Version History with comments to Excel
  1. Provide the correct SharePoint Site URL and Document Library name, then click Enter to run the script.
  2. you will be asked if you would like to export version history for all documents or for a particular document.
    • Type All to export version history for all documents.
    • Or paste the correct document URL.
export version history for a SharePoint document powershell
  1. Now, the script should loop for each document in the specified SharePoint document library to export all document version history details to CSV file.
export-sharepoint-list-version-history-powershell
Export SharePoint Version History

Where you can find the exported file location?

  1. The script will create a root folder in the “C:\” drive called “SPVersions”. In this folder, you will find a subfolder for each document library that holds another subfolder for each export operation for this document library
Export SharePoint Version History to Excel Using PowerShell

In case, you have ran this script again, it will create a new file in a new folder with the above structure.

  1. Inside, this folder, you will find the “Version.CSV” file.
Export SharePoint List Version History to Excel using PowerShell

Output

  1. Once the script is run successfully, the CSV file should be opened automatically to show the exported data.
  2. Also, it will show a detailed summary for the exported document versions with the below info:
    • Site URL: http://epm:19812/pmo/
    • Site Title: deBUG.to
    • Document Library Name: Doc Lib Get Versions Details
    • Number of Documents: 2
    • Number of Versions: 4
Export SharePoint document Version History to Excel PowerShell
Export SharePoint Version History PowerShell

By default, the exported CSV file will not be formatted, and you can see the document details and its related versions as below.

export sharepoint document version history using powershell
Export SharePoint Version History

So that, you just need to perform a bit manually format modifications to show the CSV file as below.

export-sharepoint-version-details-powershell
Export SharePoint Version History

Roadmap

In the nearest future, we’re planning to add the below features to the “SPDocVersion-Exporter” PowerShell Script:

  • Auto format for Excel Sheet.
  • Support SharePoint Online.
  • Filter by
    • date
    • TopN or
    • document name (done in version 1.5).

You can also add your suggestions and ideas on comments to enhance the SPDocVersion-Exporter.


Conclusion

The “SPDocVersion-Exporter” PowerShell Script is a well-written and tested script that helps you to easily export all document version details with comments for a specific SharePoint document library.

You might also like to read Backup all WSP SharePoint Solutions using PowerShell

See Also

1 thought on “Export SharePoint Version History to Excel Using PowerShell”

  1. Greg Dickinson

    This is a great tool! If I had any “feature requests”, they would be:

    1.) Allow an option to just export version information from a folder in the doc library
    2.) Allow an option to export custom column information with the version information.

Leave a Reply