none
Set EventFiringEnabled from Powershell?

    Question

  • Hi,

    I would like to upload documents to a document library via Powershell and doing that.. I want to disable events that might be fired.

    How can I set the EventFiringEnabled property from Powershell??

    Thanks

    Sven

    Friday, March 23, 2012 6:26 PM

Answers

  • Hi Sven!

    Not really something you generally do from PowerShell. The purpose of EventFiringEnabled is to prevent an event receiver from triggering the same event recursively.

    However,  you can switch it off for the thread upon which your PowerShell code is running.

    $myAss = [Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint");
    $type = $myAss.GetType("Microsoft.SharePoint.SPEventManager");
    $prop = $type.GetProperty([string]"EventFiringDisabled",[System.Reflection.BindingFlags] ([System.Reflection.BindingFlags]::NonPublic -bor [System.Reflection.BindingFlags]::Static));
    $prop.SetValue($null, $true, $null);
    #code to update list goes here!

    Hope this helps!

    joel


    joel
    Joel's SharePoint Architect Blog
    joelblogs.co.uk
    Want SharePoint Training?

    • Marked as answer by Sven W Saturday, March 24, 2012 12:43 PM
    Friday, March 23, 2012 10:01 PM