Monday, February 27, 2017

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()

No comments:

Post a Comment