none
Set EventFiringEnabled from Powershell?

    问题

  • 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

    2012年3月23日 18:26

答案

  • 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?

    • 已标记为答案 Sven W 2012年3月24日 12:43
    2012年3月23日 22:01