Share via


PowerShell script to find and remove duplicate items from document library

Question

Tuesday, September 2, 2014 8:43 AM

Hi Friends,

Please check this below script, It is finding the duplicate items and removing it. This script is not working to find the duplicate items from document library and remove. Can you please let me know where it is wrong.

Add-PSSnapin microsoft.sharepoint.powershell 
$web = Get-SPWeb -Identity "http://zapltvsspdev02:4333/bu/EXCO" 
$list = $web.Lists["AECI Documents"] 

$AllDuplicates = $list.Items.GetDataTable() | Group-Object INumber | 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

Note:

In the above code, duplicates are found using the "INumber" column. 

valmiki

All replies (1)

Tuesday, September 2, 2014 10:44 AM âś…Answered

check this

http://stackoverflow.com/questions/21337158/delete-duplicate-items-in-sharepoint-list