Compare SharePoint List Item Version History using PowerShell

Requirement: Compare version history data of SharePoint List items and update a metadata column based on a particular field’s value change.

A bit of background: We have a project tracking list with the “Status” column. We wanted to have an insight on when a particular item’s status was set to “Rejected”.

PowerShell to Compare Version History Data and update a column value:

As far solution to the above requirement, let’s compare list item versions to capture when a particular item’s “status” column was changed to “rejected”, and get the created date of the specific version to update the “Rejected Date” column of the list item. Let’s compare version history in SharePoint using PowerShell:

Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

$ListName = "Projects"

#Get web and List 
$Web = Get-SPWeb $SiteURL
$List = $web.Lists.TryGetList($ListName)

#Get all list items
$ListItems = $List.Items

#Iterate through each list item
Foreach($Item in $ListItems)
    #Iterate through each version
    ForEach($Version in $Item.Versions) 
        #Check if the status column is "Rejected"
        If($($version['Status']) -eq "Rejected")
            #Update Rejected Date value of the item from version
            $Item["RejectedDate"] = $($version.Created)
            Write-host "ID:$($, Version:$($version.VersionLabel), CreatedBy:-$($version.CreatedBy.User.DisplayName), Status:-$($version['Status'])"

This script compares each version of the list item and updates the “RejectedDate” column value.

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

Leave a Reply