Updated 4 weeks ago

Export SharePoint Online File Version History Report Using PowerShell

by AIMA

6 min read

No Comments

File version history plays a crucial role in maintaining the integrity and management of documents within a SharePoint site. It allows users to view previous versions of a document or list item, understand what changes were made, by whom, and when. Microsoft is continuously upgrading and refining new and improved version controls for SharePoint and OneDrive, aiming to streamline document management.

Managing version history in SharePoint is crucial for keeping track of document updates and ensuring that team collaborations run smoothly. It’s crucial to note that version history storage counts towards SharePoint Online’s overall storage quota. Monitoring the size of version histories in SharePoint Online is therefore vital to prevent sites from entering read-only mode due to insufficient storage capacity.

In this blog, we’ll guide you on various methods to access version history information within your SharePoint Online sites.

How to View File Version History in SharePoint?

Here are the methods to get file version history in SharePoint Online:

Viewing version history via SharePoint admin center: Login to the SharePoint admin center -> Active sites -> Select the site of interest -> Document library -> Select a document -> More options (…) -> Version history. Yet, manually navigating through this process can become time-consuming, especially when reviewing multiple versions.

Check SharePoint version history using PowerShell: You can utilize the Get-PnPListItem cmdlet along with the -FileVersions property to retrieve the version history of individual documents in SharePoint Online. While Microsoft provides the necessary cmdlets, you need to pass each site URL to retrieve all site documents’ version details.

Our custom PowerShell script streamlines this process for Microsoft 365 admins by seamlessly exporting the version history of items from their SharePoint Online site into a CSV file.

Script Highlights

  1. Retrieves file version history for all documents in a site.
  2. Exports file version history for a list of sites.
  3. Exports version history information for files uploaded by a specific user.
  4. Finds files with larger version history based on your input.
  5. File size can be exported in preferred units such as MB, KB, B, and GB.
  6. Automatically installs the PnP PowerShell module (if not installed already) upon your confirmation.
  7. The script can be executed with an MFA-enabled account too.
  8. Exports report results as a CSV file.
  9. The script is scheduler friendly.
  10. It can be executed with certificate-based authentication (CBA) too.

SPO File Version History Report – Sample Output

The script exports the document version history of all documents in a specific SharePoint site with the following attributes.

  • Site
  • Library
  • File Name
  • Major Versions
  • Minor Versions
  • Version Count
  • File Size
  • Version History Size
  • Total File Size Including Version History
  • Created By
  • Created Date
  • Last Modified By
  • Last Modified Date

The exported SharePoint version size report looks like the screenshot below.

File version history report

Generating a Detailed Version History Report in SPO – Script Execution Steps

  1. Download the script.
  2. Start the Windows PowerShell.
  3. Select any of the methods provided to execute the script.

Method 1: You can run the script with MFA and non-MFA accounts.

When you run this script, you’ll be prompted to enter the URL of the SharePoint site. It then exports the version history for all documents within that specific site.

Important: While running the script, authorization is required for the specified site, regardless of MFA status. To avoid this issue, use the second method, which lets you gather data from the site without any authorization checks or errors.

Method 2: You also have the option to run the script using certificate-based authentication. When you want to run the script unattended, you can choose this method.

To use certificates, you must register the app in Microsoft Entra.

Note – Depending on your requirements, you can create a self-signed certificate.

What You’ll Find in the Script:

The script includes predefined filters designed to meet your specific needs. Here are some scenarios where it performs exceptionally well:

Get File Version History of Specific Sites in SharePoint Online (Input CSV)

By default, the script generates a version history report for all documents in the SharePoint site, tailored to user input. If you need to generate a report for a list of sites, you can utilize the ImportCsv parameter for more focused analysis. For example:

The file must follow the format below: Site names separated by a new line with “SiteUrl” as header. Not including this header will result in errors when running the script.

File version history report

The resulting report will show all documents and their version history details for the list of sites.

Note: You can also verify the files & folder count, size, etc., of all document library in SharePoint Online to identify unwanted storage consumption.

Retrieve Files with Specific Version Count & Higher in SharePoint Online

Ensuring proper version control and auditing involves keeping track of the version counts of documents stored in SharePoint Online. You can execute the script with the -VersionCount parameter to generate a list of files that have a specific version count or higher, helping you identify files with multiple versions for review and management.

When you run this script, you’ll be prompted to enter the URL of the SharePoint site. Alternatively, you can pass the URL using the -SiteUrl parameter during script execution.

The resulting report shows all the documents in the specific site “test” having version count 34 and higher. Or, if you want to check for multiple sites, you can pass sites through CSV file.

Get Version History Details of Files Created by a Specific User

Tracking file version history by specific users is crucial for monitoring contributions, identifying changes, and ensuring accountability in collaborative environments. By using the -UserId parameter, you can generate a detailed version history report of files created by a specific user.

This example fetches and displays the version history details of files created by Alex.

To retrieve results for a specific site, use the –SiteUrl parameter in the cmdlet. For multiple sites, you can use the -ImportCsv.

Retrieve File Version History with Custom Size Units in SharePoint Online

Efficient data management often requires understanding the storage impact of files in different units. By specifying the -Unit parameter, you can format the file version history report in your desired unit (B, KB, MB, GB), making it easier to manage and analyze storage consumption.

This example exports the report with file size, version size, and total size in the unit “GB”.

Note: To retrieve file version history with custom sizes for a particular site, pass the SiteUrl into the cmdlet or use a CSV file path for multiple sites.

Schedule SharePoint Version History Report Using PowerShell

The script is scheduler friendly. You can schedule the script using the Task scheduler or Azure Automation. To schedule the script, you can use the following format.

If you want to automate version history report for multiple sites, you can pass multiple site URLs through -ImportCSV instead of –SiteUrl.

Streamline Your SharePoint Online Monitoring with AdminDroid

Ensuring compliance and security in SharePoint requires effective monitoring of site activities. PowerShell scripts, while useful, can be complex, often falling short in providing detailed insights. Thats where AdminDroid steps in to save the day! AdminDroid’s SharePoint Online auditing tool lets you monitor unexpected activities and respond fast. It offers a comprehensive solution with its extensive SharePoint Online reports, delivering clear and actionable insights:

SharePoint Versioning Reports

  • Lists with no versioning
  • Document libraries with no versioning
  • Version recycled files
  • All minor version recycled files

SharePoint Online Site Reports

  • All SharePoint Sites
  • Recently Created Sites
  • Sites Over Warning Quota

External User Activities

  • Files Shared with External Users
  • Files Shared with Anonymous Access
  • Site Invitations Shared with External Users
  • External Members Added/Removed from SPO Groups and more..

SharePoint site collections report by AdminDroid

Moreover, the SharePoint Online dashboard provided by AdminDroid gives you an engaging, clear view of your M365 environment. It simplifies SharePoint Online management, making tasks easier and boosting security.

With over 1800 reports and more than 30 dashboards, AdminDroid covers Exchange Online, SharePoint Online, Microsoft Teams, OneDrive for Business, and more. Start your journey towards optimized Microsoft 365 management with AdminDroid. Try our 15-day free trial and experience the difference for yourself! Download AdminDroid today and elevate your SharePoint monitoring and management.

We trust that this blog has provided you with the information needed to effectively retrieve SharePoint version history using PowerShell. For those looking to explore their SharePoint environment further, a list of essential PowerShell scripts to list all sites and subsites might be helpful. Thanks for reading. If you have more questions, please reach out to us through the comment section below.

Share article