Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

$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
    # | % { $_.Delete() } #Uncomment this to perform delete.

Thanks to this blog post for showing the way: Finding (and Deleting) Duplicate Files

share|improve this answer
    
Great answer, was just about to start writing this PS myself so you've saved me time :-) –  Brian Scott Apr 9 '12 at 15:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.