Thursday, October 1, 2015

Compare SharePoint List Items using PowerShell

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

Solution: Lets use PowerShell script to compare and extract the difference between SharePoint lists!

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
#Variables for Processing
$SiteURL = "http://projects.crescent.com"
$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
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



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...