Find and remove duplicated records in SharePoint list
Today I was surprised to see duplicated records in SharePoint list which I imported and updated from XML-files. So I started to find a solution to find duplicated records, see them and delete.
Below I post a powershell script to find and remove duplicated records. It was found using google-search, and added string not to remove duplicated records immediately, but to see them at first.
Add-PSSnapin microsoft.sharepoint.powershell $web = Get-SPWeb -Identity http://spdev/vc $list = $web.Lists["companies"] $AllDuplicates = $list.Items.GetDataTable() | Group-Object title | where {$_.count -gt 1} $count = 1 $max = $AllDuplicates.Count foreach($duplicate in $AllDuplicates) { #uncomment string below to delete duplicated records #$duplicate.group | Select-Object -Skip 1 | % {$list.GetItemById($_.ID).Delete()} #string below displays found duplicated records Write-Host $duplicate.Name } Remove-PsSnapin Microsoft.SharePoint.PowerShell
So, to be clear, does this loop until all duplicates are gone? I have some records in the list 3 times; need to remove any 2 of them.
Comment by mefreemantle — May 26, 2017 @ 4:55 pm