Compare SharePoint List Items using PowerShell

Requirement: We’ve two task lists with hundreds of rows in them. I wanted to compare these two SharePoint Lists and extract the difference from both of them.


Let’s use the PowerShell script to compare and extract the difference between SharePoint lists!

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Variables for Processing
$SiteURL = ""
$ListOneName ="Team One Tasks"
$ListTwoName ="Tasks Two Tasks"
$ColumnToCompare="Task Name"

#Get site and List objects
$Web = Get-SPWeb $SiteURL
$ListOne = $web.lists[$ListOneName]
$ListTwo = $web.lists[$ListTwoName]

#Fetch specifc Column Values from each lists to compare
$ListOneValues = @()
$ListTwoValues = @()

$ListOne.Items| foreach { $ListOneValues+= $_[$ColumnToCompare] }
$ListTwo.Items | foreach { $ListTwoValues+= $_[$ColumnToCompare] }

Compare-Object $ListOneValues $ListTwoValues # -PassThru

Output: Here, the InputObject column gives the difference.

Compare SharePoint Lists using PowerShell

The SideIndicator simply denotes where is the difference is.

  • <= – Difference is in Left side – first object we compare
  • => – Difference is in the Right side – Second object in the comparison

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

4 thoughts on “Compare SharePoint List Items using PowerShell

  • how I can compare a list item with a folder name in sharepoint using PnP?

  • I have tried to do this in PnP but my script didnt work. Can you help?

  • This doesn’t explain:

    Where does the Microsoft.SharePoint.PowerShell snap-in come from and how do I get it?

    • Microsoft.SharePoint.PowerShell snap-in comes with SharePoint installation. Run this code from any of App/Web Server.


Leave a Reply

Your email address will not be published. Required fields are marked *