Tuesday, November 11, 2014

SharePoint Event Receivers that are running on a List

It is tough to find out running "Event Receivers" for a SharePoint list.
Here is a way using Power Shell script to know the Event Receivers bound to a List:

$web = Get-SPWeb -Identity "http://pc.gn.com/sites/CO"
$list = $web.Lists["Order List"]
$list.EventReceivers


Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$spWeb = Get-SPWeb -Identity "http://pc.gn.com/sites/CO"
$spList = $spWeb.Lists["Order List"]
$evts = $spList.EventReceivers
$evts
Write-Host("..." + $evts.Count)
if ($evts.Count -gt 0) {
            foreach ($evt in $evts) {
                Write-Host("..." + $spList.RootFolder.ServerRelativeUrl + ", " + $evt.Type)
            }
        }


TO delete an event receiver from a List:
Once you confirm  the event receivers, use below to delete them
Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$spWeb = Get-SPWeb -Identity "your site url"
$spList = $spWeb.Lists["TrackTravel"]
$evts = $spList.EventReceivers | where {$_.Assembly -eq ""your assembly"}
$evts
if ($evts.Count -gt 0) {
            foreach ($evt in $evts) {
                Write-Host("Deleting..." + $spList.RootFolder.ServerRelativeUrl + ", " + $evt.Type)
                $evt.Delete()
            }
        }

And the other way is:
To know the Event Receivers bound to a List and Events that ran on a List Item (Title: MI4803)
USE WSS_Content_XXX
SELECT * FROM EventReceivers WITH (NOLOCK)
where Class like 'GN.SP2010%'

select * from dbo.EventLog
where ListId = '1648253C-ED8F-44AE-B2EB-A19238102B41'
and ItemName = 'MI4803'

No comments:

Post a Comment