#check to see
if the PowerShell Snapin is added
if ((Get - PSSnapin | Where
{
$_.Name - eq "Microsoft.SharePoint.PowerShell"
}) - eq $null)
{
Add - PSSnapin Microsoft.SharePoint.PowerShell;
}
##SharePoint DLL
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
function RemoveEventReceiver($List, $EventReceiverId)
{
$eventReceivers = $List.EventReceivers | Where
{
$_.Id - eq $EventReceiverId
}
if ($eventReceivers)
{
foreach($receiver in $eventReceivers)
{
Write - Host "Deleting Event Receiver from "
$List.RootFolder.ServerRelativeUrl - ForegroundColor Yellow
$receiver.Delete()
Write - Host Deleted event receiver successfully. - ForegroundColor Green
}
}
else
{
Write - Host No Event Receivers on List with id $EventReceiverId present - ForegroundColor Yellow
}
}
write - host "Please Enter Site collection url" - foregroundcolor Yellow
$sourceSiteURL = Read - Host
write - host "Please Enter Event Receiver Id" - foregroundcolor Yellow
$Id = Read - Host
write - host "Please Enter Document Library Title" - foregroundcolor Yellow
$docLibrary = Read - Host
$siteColl = Get - SPSite $sourceSiteURL - ErrorAction silentlycontinue
if ($siteColl - ne $null)
{
$spweb = $siteColl.OpenWeb()
$TestList = $spweb.Lists[$docLibrary]
if ($TestList - ne $null)
{
Write - Host List found. - foregroundcolor Yellow
RemoveEventReceiver $TestList $Id
}
}This PowerShell script will help remove event receiver from Document Library. Inputs required - Site Collection to operate on, Document Library Title and Event receiver ID to remove
