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?

link|improve this question

75% accept rate
feedback

1 Answer

$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

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

Your Answer

 
or
required, but never shown

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