How to Update the SequenceNumber on an SPEventReceiver via PowerShell
The following will demonstrate how to update the SequenceNumber on an SPEventReceiver via Windows PowerShell.
First, we need to get a reference to the SPList that has our SPEventReceiver registered on it, which can be done with the following PowerShell sample:
PS C:\> $web = Get-SPWeb https://sharepoint2010 PS C:\> $list = $web.Lists["Shared Documents"]
We now have a reference to the "Shared Documents" library, set to variable $list.
We can then display all the event receivers registered on the "Shared Documents" library by executing:
PS C:\> $list.EventReceivers
You will now see a list of all event receivers registered for the "Shared Documents" document library. The output will be similar to the following:
Id | : | ce9f574e-1c7a-4f4e-9670-0420765bc291 |
Name | : | Sample Event Receiver |
SiteId | : | e6ff4ed6-2e67-4f58-a4c2-0e162b520a7a |
WebId | : | 419b5b6f-d7fa-44cb-8bb6-daafc7219d60 |
HostId | : | 9810722d-58bc-4ae7-85c9-6573bea10c0e |
HostType | : | List |
ParentHostId | : | 00000000-0000-0000-0000-000000000000 |
ParentHostType | : | Site |
Synchronization | : | Synchronous |
Type | : | ItemAdding |
SequenceNumber | : | 10000 |
Assembly | : | Microsoft.SharePoint.Sample.EventReceiver, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a53c319f89b035f3 |
Class | : | Microsoft.SharePoint.Sample.EventReceiver.SampleEventReceiver |
We can now use the Id
value from the output above and bind to a specific event receiver, which we need to do because we could have more than one event receiver registered on a this list.
PS C:\> $eventReceiver = $list.EventReceivers[[GUID]"ce9f574e-1c7a-4f4e-9670-0420765bc291"]
You could also use the zero-based index of the event receiver, like in this example:
PS C:\> $eventReceiver = $list.EventReceivers[0]
We now have a reference to the event receiver we are trying to update, set to the $eventReceiver
variable. We can update the SequenceNumber value from the current value of 10000, to our new value of 50000.
PS C:\> $eventReceiver.SequenceNumber = 50000 PS C:\> $eventReceiver.Update()
The sequence number is now updated and saved on our list event receiver.
This example will update the sequence number on a web event receiver.
PS C:\> $web = Get-SPWeb https://sharepoint2010 PS C:\> $web.EventReceivers PS C:\> $eventReceiver = $web.EventReceivers[0] PS C:\> $eventReceiver.SequenceNumber = 10002 PS C:\> $eventReceiver.Update()
Comments
- Anonymous
January 27, 2014
After invoking $eventReceiver.Update() I've got error message: Exception calling "Update" with "0" argument(s): "No parameterless constructor defined for this object." What's going on?