Introduction
Event receivers are methods executed when a specific trigger occurs in SharePoint. For instance, an item is added, based on which a code block is executed. Event receivers have always been a very useful point of entry for functionalities in SharePoint.
Follow along to find out how you can compile the list of event receivers in your site collection as per the below code.
Code
- if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)
- {
- Add-PSSnapin "Microsoft.SharePoint.PowerShell"
- }
-
- #Enter your site collection below
- $site = Get-SPSite -Identity http:
-
- foreach ( $web in $site.AllWebs )
- {
- Write-Host "Looking in web: " $web.Url
- foreach ($list in $web.Lists)
- {
- if ($list.EventReceivers.Count -gt 0){
- Write-Host $list.Title " has " $list.EventReceivers.Count " event receiver(s)"
- Write-Host "***********************************************************************************"
- $list.EventReceivers.Name
- Write-Host "***********************************************************************************"
- }
- }
- }
Usage
Just enter the site collection URL where you want to identify the event receivers and execute the code. The list containing event receivers will be displayed, along with the count and name of event receivers.
Output
The output will be printed on the screen. If needed, the code can be modified to direct the output to a text file also.
Summary
In this article, we learned how to view all of the event receivers for a site collection in SharePoint.