Sharepoint Find and remove duplicates in the list using Powershell

Add-PSSnapin microsoft.sharepoint.powershell
$web = Get-SPWeb -Identity “”
$list = $web.Lists[“List Name”]

$AllDuplicates = $list.Items.GetDataTable() | Group-Object title | where {$_.count -gt 1}
$count = 1
$max = $AllDuplicates.Count
foreach($duplicate in $AllDuplicates)
{
$duplicate.group | Select-Object -Skip 1 | % {$list.GetItemById($_.ID).Delete()}
Write-Progress -PercentComplete ($count / $max * 100) -Activity “$count duplicates removed” -Status “In Progress”
$count++
}
Remove-PsSnapin Microsoft.SharePoint.PowerShell

Leave a Reply

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