In this article I want to share how to use Power Shell to attach event receiver to a list, provide configuration values from an xml.And also, how to use Power Shell to view a list of existing event receivers.To copy the information of existing event receivers, insert a line such as # Add the Share Point module if ((Get-PSSnapin -Name Microsoft. Power Shell -Error Action Silently Continue) -eq $null ) #Read the data from the Xml file $config = (Get-Content "Config.xml") if ($config -eq $null ) $site = $config. Event Handler) We could have probably used code (feature activated code or console application) to attach the event handler.
The solution is to manually set up the Pages library the same way Microsoft does by adding two event receivers, changing some columns from hidden to visible and adding them to the default view.
Note: This example uses commands from the Office Dev Pn P Power Shell library, ex. I recommend using this library for working this Power Shell and Share Point (both Online and On-Premises).
Below Power Shell attaches the event handler to a document library.
I have initialized a sequence number and increment this number every time we attach an event handler.
In order to confirm that the event handler was not attached, I wrote a Power Shell script to list all the event handlers attached to that particular library.
I loop the Event Receivers in descending order of index.
Well we cannot change the Share Point code so we have to find a way to update our event receiver code (which is the one with index “1” above).
Also note that the Edit uses exactly the SPList Item.
Scheduling is easily enabled through the web interface when configuring the “Pages” library, but when deploying solutions using Power Shell, this must be automated as part of the configuration.
Unfortunately, as many other sources also state, this is not directly supported in the Client Side API (CSOM).
This is because, we need to specify a different sequence number for each event handler to indicate the order in which they should be executed. Web Url; Write-Host($web Url); ## open the web site Write-Host "Opening web $web Url" -nonewline $web = Get-SPWeb $web Url Write-Host "$web" Write-host " – done " -foreground green foreach($handler in $site.