Lately i had a bug that time-to-time added duplicate event receiver entries in SPEventReceiverDefinitionCollection.
So how do i easily enumerate and remove these duplicate entries?
Lately i had a bug that time-to-time added duplicate event receiver entries in SPEventReceiverDefinitionCollection.
So how do i easily enumerate and remove these duplicate entries?
$eventReceiversToDelete = $list.EventReceivers |
group-object assembly, class, type | #Groups event receiver by assembly/class/type
? { $_.Count -gt 1 } | #If any of assembly/class/type pairs are encountered more than once, we have a duplicate
% { $_.Group[1..100] } #enumerate starting from second item (indexed at 1), so we don't delete event receiver completely
for ($i = $eventReceiversToDelete.Count - 1; $i -ge 0; $i--) {
Write-Host "Deleting $($eventReceiversToDelete[$i].Type) Event Receiver $($eventReceiversToDelete[$i].Name)" }
#Uncomment to delete
#$eventReceiversToDelete[$i].Delete()
}
Thanks to this blog post for showing the way: Finding (and Deleting) Duplicate Files