magritton
4/12/2017 - 11:01 PM

This finds and recycles SharePoint list items. Also an example of grouping items.

This finds and recycles SharePoint list items. Also an example of grouping items.

$web = Get-SPWeb -Identity https://xxxx 
$list = $web.Lists["Archive"]

$AllDuplicates = $list.Items.GetDataTable() | Group-Object title | where {$_.count -gt 1}

$max = $AllDuplicates.Count

#Retrieve all event receivers associated with the list
$list.EventReceivers | Select Id, Type, Assembly, Class
$confirmation = Read-Host "press any key to continue......."

foreach($duplicate in $AllDuplicates) 
{ 
$items = $duplicate.group | Select-Object -Skip 1 | % {$list.GetItemById($_.ID)}
foreach($item in $items)
{
	$item["Title"]
	$item["Title"] | out-file "f:\temp\dupsdeleted.txt" -append
	$item.Recycle()
}
if($max -gt 0){
	Write-Progress -PercentComplete ($count / $max * 100) -Activity "$count duplicates removed" -Status "In Progress"
}

$count++ 
}

$list.EventReceivers | Select Id, Type, Assembly, Class