Use PowerShell to Compare Two SharePoint Lists

What if, for some random reason you wanted to compare two SharePoint Lists or Libraries and find the differences.

For the setup, I created two Lists (A and B).  I then added a few items to the Lists. Notice, that List A has two extra items, 6 and 7.



$mSite = Get-SPweb ""
$aList = $mSite.lists["A"]
$bList = $mSite.lists["B"]

$arrA = @()
$arrB = @()

foreach($iA in $aList.Items)
 $arrA += $iA["Title"]

foreach($iB in $bList.Items)
 $arrB += $iB["Title"]

$c = Compare-Object -ReferenceObject $arrA -DifferenceObject $arrB -PassThru
Write-Host $c

Output of the above script is: 6 7

More about the Compare-Object cmdlet:


Leave a Reply

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