Restoring Previous Versions of Items in a SharePoint List Using PnP PowerShell
When working with SharePoint lists, there might be times when you need to restore items to a previous version. Whether it’s due to an error, unwanted changes, or simply needing to revert to an earlier state, SharePoint’s versioning feature is a lifesaver. I used the script to undo bulk changes made by a Power Automate flow after the process failed halfway due to some data needing correction. For data integrity, the bulk update needed to be undone before running the Power Automate flow again after the data corrections were made.
This posts covers how to restore previous versions of items in a SharePoint list using PnP PowerShell
.
PowerShell Script
Below is a sample script which retrieves data based on a condition and checked whether a version was created on a particular date by the system account as a result of automation process and restore a previous version of the list item. Amend the script as per your requirements.
The cmdlet Restore-PnPListItemVersion
below does the trick to restore the previous version of an item by substracting 1 from the item property VersionLabel
.
Restore-PnPListItemVersion -List $List -Identity $itemId -Version ($_.VersionLabel - 1).ToString(".0") -Force
The whole sample script is below. Ensure to install PnP PowerShell and have access to the SharePoint List.
An example of the output: