Tuesday, August 11, 2015

Removing Event Receiver from SharePoint list

Introduction

As we know about event receiver in SharePoint. I am going to share a powershell script which is used to remove an associated Event Receiver

Script 

function RemovingEventReceiver($siteURL ,$listName, $eName)
{
$spweb= Get-SPWeb $siteURL
$list = $spweb.Lists[$listName]

 $noe = $list.EventReceivers.Count

  if ($noe -gt 0)
{
   for( $index = $noe -1; $index -gt -1; $index–-)
   {
      $receiver = $list.EventReceivers[$index] ;
      $name = $receiver.Name
      $typ = $receiver.Type ;
 
      if ($name -eq $eName)  
      {
         $receiver.Delete()
         Write-Host "Event receiver " $name " is deleted from " $listName -ForegroundColor Green
      }
   }
}
}
$web = Read-Host "Enter site URL : "

RemovingEventReceiver $web "YourListName" "EventReceiverName"

No comments:

Post a Comment