I have a Content Database that contains Event Receivers referring to a Solution / Feature that was incorrectly removed. These Event Receivers are embedded in every Content Type in my Site Collection and prevent me from creating new Sites.
Using SharePoint Manager 2010 I can view the references using "Site Collection > Content Types > Event Receivers", but not delete / remove them.
I found a similar question here: Content Type Event Receivers Impossible to Remove, but am unable to remove the event receivers.
Is there anyone here that can help me delete these event receivers?
Answer provided by Hugh Wood
Powershell code used for the deletion of event-receivers in the announcement content type:
$site = Get-SPSite "http://url"
$web = $site.RootWeb
$ct = $web.ContentTypes["Announcement"]
$ct.EventReceivers
$ct.EventReceivers[0].delete()
$ct.update()
I created the following powershell script to remove the Event Receivers from the Content Types. The script requires the name of the Content Type as a parameter. It counts the total number of event receivers registered and deletes them via a while-loop.
Attention: This script does not validate the Event Receiver name. It deletes all Event Receivers found for the given Content Type name.
Param(
[parameter(Mandatory=$true)]
[alias("ContentTypeName")]
$r_ContentTypeName)
$r_input= $r_ContentTypeName
echo $r_ContentTypeName
#$r_input= Read-Host 'What is the Content Type Name?'
$site = Get-SPSite "URLGoesHere"
$web = $site.RootWeb
$ct = $web.ContentTypes[$invoer]
$ct.EventReceivers
$i = 0
$aantal = $ct.eventreceivers.count
while ($i -le $aantal)
{
$ct.EventReceivers[0].delete()
$ct.update()
$i++
}
$ct.update()
Please post your adaptation of this script to help other people experiencing this issue.