Friday 31 August 2012

PowerShell - Event Receivers on SharePoint List

There are times when you want to check which event receivers are attached to a SharePoint list.   This can be easily achieved through use of a PowerShell script.

$spWeb = Get-SPWeb Identity http://sharepoint
$spList = $spWeb.Lists["My List"]  
$spList.EventReceivers | Select Name, Assembly, Type

There are also times when you might want to remove any event receivers from the list

$spWeb = Get-SPWeb Identity http://sharepoint
$spList = $spWeb.Lists["My List"]  
$spList.EventReceivers | Select Name, Assembly, Type

$eventsCount = $spList.EventReceivers.Count

for ($i = $eventsCount-1; $i -ge 0; $i--)
{
    $spList.EventReceivers[$i].Delete()
}

$spList.Update()

2 comments:

  1. Identity should be prefixed with hyphens(-Identity).

    ReplyDelete
  2. Thanks for this! Two things:

    1. $spList.Update() should be inside the FOR loop
    2. Your script should end with $spWeb.Dispose()

    ReplyDelete