You can add Custom Event Receivers to a List in SharePoint 2010 using Windows PowerShell. Event Receivers can be used to execute code before or after an Item is created, updated, or deleted. It’s possible to run the code either Synchronous or Asynchronous. The example below demonstrates how you can add a Custom Event Receiver to a List in SharePoint 2010:
PS > $spWeb = Get-SPWeb http://SP01.powershell.nu
PS > $spList = $spWeb.Lists["Tasks"]
PS > $spEvent.Name = "My Event"
PS > $spEvent.Type = "ItemAdded"
PS > $spEvent.Synchronization = "Asynchronous"
PS > $spEvent.SequenceNumber = 3000
PS > $spEvent.Assembly = "My.SharePoint.Event, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a8b0a959bb9389c6"
PS > $spEvent.Class = "My.SharePoint.Event.PowerShellEventReceiver"
PS > $spEvent.Update()
PS > $spWeb.Dispose()
The Type Property will accept a couple of different values such as: Item Added, Item Adding, Field Added and more. To see a complete list of the supported types, you can run the following command in PowerShell:
[System.Enum]::GetNames("Microsoft.SharePoint.SPEventReceiverType")
ReTweet this Tip!
Posted
Apr 09 2012, 06:00 AM
by
sos