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.
Consider you have a SharePoint Document Library that holds several documents
![Export SharePoint Version History to Excel Using PowerShell get sharepoint document versions powershell](https://i0.wp.com/spgeeks.devoworx.com/wp-content/uploads/2021/04/get-sharepoint-document-versions-powershell.png?resize=607%2C295&ssl=1)
In this SharePoint document Library, the Document Version History and Checked-Out settings has been enabled as shown below:
![Export SharePoint Version History to Excel Using PowerShell sharepoint list version history export to excel](https://i0.wp.com/spgeeks.devoworx.com/wp-content/uploads/2021/03/sharepoint-list-version-history-export-to-excel.png?resize=467%2C654&ssl=1)
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 SharePoint Version History to Excel Using PowerShell export all Versions with comments in SharePoint Document Library using PowerShell](https://i0.wp.com/spgeeks.devoworx.com/wp-content/uploads/2021/03/export-all-Versions-with-comments-in-SharePoint-Document-Library-using-PowerShell.png?resize=526%2C302&ssl=1)
Alternatively, you can also explore the SharePoint Document Versions History as below:
![Export SharePoint Version History to Excel Using PowerShell Export SharePoint Version History to Excel Using PowerShell](https://i0.wp.com/spgeeks.devoworx.com/wp-content/uploads/2021/03/sharepoint-document-library-version-history-export-to-excel.png?resize=740%2C592&ssl=1)
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 Export SharePoint Version History to Excel Using PowerShell](https://i0.wp.com/spgeeks.devoworx.com/wp-content/uploads/2021/03/export-Version-details-for-each-Document-in-SharePoint-Document-Library.png?resize=627%2C469&ssl=1)
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 Version History to Excel Using PowerShell Export SharePoint document Version History to Excel PowerShell](https://i0.wp.com/spgeeks.devoworx.com/wp-content/uploads/2021/04/Export-SharePoint-document-Version-History-to-Excel-PowerShell.png?resize=569%2C995&ssl=1)
Note: This script was previously published on TechNet Gallery in 2017 and was improved upon and published on PowerShell Gallery in 2021.
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
- 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.
- Show all version history details with comments for each document like
- Version ID,
- Version Title,
- Modified By,
- Modified Date,
- Version Size,
- Check-In Comment.
- Show the document details first then list all related version details.
![Export SharePoint Version History to Excel Using PowerShell export sharepoint version details powershell](https://i0.wp.com/spgeeks.devoworx.com/wp-content/uploads/2021/04/export-sharepoint-version-details-powershell.png?resize=865%2C264&ssl=1)
- Show the detailed steps for each document.
![Export SharePoint Version History to Excel Using PowerShell export list version details in sharepoint powershell](https://i0.wp.com/spgeeks.devoworx.com/wp-content/uploads/2021/04/export-list-version-details-in-sharepoint-powershell.png?resize=544%2C97&ssl=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 to Excel using PowerShell](https://i0.wp.com/spgeeks.devoworx.com/wp-content/uploads/2021/04/Export-SharePoint-Version-History-to-Excel-PowerShell.png?resize=616%2C199&ssl=1)
Validation and Verification
- Perform validation and verification for the SharePoint Site URL, the Document Library Name, and the Exported file Path.
![Export SharePoint Version History to Excel Using PowerShell check if SharePoint URL found powershell](https://i0.wp.com/spgeeks.devoworx.com/wp-content/uploads/2021/04/check-if-SharePoint-URL-found-powershell.png?resize=623%2C251&ssl=1)
- It also checks if the version settings for a document library have been enabled or not before proceed.
![Export SharePoint Version History to Excel Using PowerShell Check if the version settings enabled for a document library in SharePoint using PowerShell](https://i0.wp.com/spgeeks.devoworx.com/wp-content/uploads/2021/03/Check-if-the-version-settings-enabled-for-a-document-library-in-SharePoint-using-PowerShell.png?resize=674%2C114&ssl=1)
If the versioning setting is not enabled, the script will automatically open the Document Library Versioning Settings to enable it.
![Export SharePoint Version History to Excel Using PowerShell sharepoint list version history export to excel](https://i0.wp.com/spgeeks.devoworx.com/wp-content/uploads/2021/04/sharepoint-list-version-history-export-to-excel-edited.png?resize=467%2C292&ssl=1)
Versioning
- Build an independent folder for each document library.
- Organize each result in a particular file classified by the current date and time.
- Don’t overwrite old files.
![Export SharePoint Version History to Excel Using PowerShell powershell export sharepoint list library](https://i0.wp.com/spgeeks.devoworx.com/wp-content/uploads/2021/04/powershell-export-sharepoint-list-library.png?resize=553%2C298&ssl=1)
Flexible
The SPDocVersion-Exporter provides you two options to export SharePoint Version History :
- Export the version history for ALL documents.
- Export the version history for a particular document.
![Export SharePoint Version History to Excel Using PowerShell export version history for a SharePoint document powershell](https://i0.wp.com/spgeeks.devoworx.com/wp-content/uploads/2021/04/export-version-history-for-a-SharePoint-document-powershell.png?resize=718%2C109&ssl=1)
Easy to use
- No additional configuration on your side, you only need to install SPDocVersion-Exporter script from PowerShell Gallery,
- Provides only two parameters (SharePoint Site URL, Document Library Name).
- Type “All” to export SharePoint Version History for all documents or paste the “document URL” to export a specific document version.
- Once the script is run successfully, the exported file will be opened automatically to show the result.
![Export SharePoint Version History to Excel Using PowerShell Export SharePoint document Version History to Excel PowerShell](https://i0.wp.com/spgeeks.devoworx.com/wp-content/uploads/2021/04/Export-SharePoint-document-Version-History-to-Excel-PowerShell-edited.png?resize=569%2C356&ssl=1)
How to use SPDocVersion-Exporter?
To export SharePoint Document Library Version Details to Excel using “SPDocVersion-Exporter”, you should do the following:
- Open the Windows PowerShell As administrator.
![Export SharePoint Version History to Excel Using PowerShell run Windows PowerShell as Administrator](https://i0.wp.com/spgeeks.devoworx.com/wp-content/uploads/2021/04/run-windows-PowerShell-as-Administrator.png?resize=353%2C268&ssl=1)
- Type the below cmdlet to install the “SPDocVersion-Exporter” script.
Install-Script -Name SPDocVersion-Exporter
![Export SharePoint Version History to Excel Using PowerShell install script from PowerShell Gallery](https://i0.wp.com/spgeeks.devoworx.com/wp-content/uploads/2021/04/install-script-from-PowerShell-Gallery-1.png?resize=559%2C148&ssl=1)
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
- After installing the script, type the below cmdlet to run it.
SPDocVersion-Exporter
- 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)
![Export SharePoint Version History to Excel Using PowerShell PowerShell Export SharePoint Version History with comments to Excel](https://i0.wp.com/spgeeks.devoworx.com/wp-content/uploads/2021/04/sharepoint-version-history-export-powershell.png?resize=565%2C186&ssl=1)
- Provide the correct SharePoint Site URL and Document Library name, then click Enter to run the script.
- 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 SharePoint Version History to Excel Using PowerShell export version history for a SharePoint document powershell](https://i0.wp.com/spgeeks.devoworx.com/wp-content/uploads/2021/04/export-version-history-for-a-SharePoint-document-powershell.png?resize=718%2C109&ssl=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 Version History to Excel Using PowerShell export-sharepoint-list-version-history-powershell](https://i0.wp.com/spgeeks.devoworx.com/wp-content/uploads/2021/04/export-sharepoint-list-version-history-powershell-edited.png?resize=633%2C396&ssl=1)
Where you can find the exported file location?
- 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 Export SharePoint Version History to Excel Using PowerShell](https://i0.wp.com/spgeeks.devoworx.com/wp-content/uploads/2021/04/powershell-export-sharepoint-list-library.png?resize=553%2C298&ssl=1)
In case, you have ran this script again, it will create a new file in a new folder with the above structure.
- Inside, this folder, you will find the “Version.CSV” file.
![Export SharePoint Version History to Excel Using PowerShell Export SharePoint List Version History to Excel using PowerShell](https://i0.wp.com/spgeeks.devoworx.com/wp-content/uploads/2021/03/Export-SharePoint-List-Version-History-to-Excel-using-PowerShell.png?resize=480%2C211&ssl=1)
Output
- Once the script is run successfully, the CSV file should be opened automatically to show the exported data.
- 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 Version History to Excel Using PowerShell Export SharePoint document Version History to Excel PowerShell](https://i0.wp.com/spgeeks.devoworx.com/wp-content/uploads/2021/04/SPDocVersion-Exporter.gif?resize=840%2C595&ssl=1)
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 Version History to Excel Using PowerShell export sharepoint document version history using powershell](https://i0.wp.com/spgeeks.devoworx.com/wp-content/uploads/2021/03/export-sharepoint-document-version-history-using-powershell.png?resize=703%2C247&ssl=1)
So that, you just need to perform a bit manually format modifications to show the CSV file as below.
![Export SharePoint Version History to Excel Using PowerShell export-sharepoint-version-details-powershell](https://i0.wp.com/spgeeks.devoworx.com/wp-content/uploads/2021/04/export-sharepoint-version-details-powershell.png?resize=865%2C264&ssl=1)
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
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.