Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

How can I call DisableEventFiring using PowerShell?

C# code like this :

Type typeInfo = typeof(SPEventReceiverBase); 
MethodInfo disable = typeInfo.GetMethod("DisableEventFiring", BindingFlags.Instance | BindingFlags.NonPublic);
SPEventReceiverBase receiver = new SPEventReceiverBase();
 disable.Invoke(receiver, null);

I need do something like this using PS

share|improve this question

2 Answers 2

You can call this function only from inside an event receiver but not via powershell.

If you want to prevent a event receiver from being fired, you can use a power shell script to remove it. http://blogs.msdn.com/b/sharepoint_bar__grill/archive/2011/12/12/10151733.aspx

Another option is to SharePoint Manager 2010 to remove the Event receiver. http://spm.codeplex.com

share|improve this answer

You Shouldn't.

DisableEventFiring is only meant to be used inside EventReceivers. The main purpose is to prevent looping when they update items.

If you really REALLY want then it's almost identical to you c# code:

$receiver = New-Object "Microsoft.SharePoint.SPEventReceiverBase"
$type = $receiver.GetType()
[System.Reflection.BindingFlags]$flags = [System.Reflection.BindingFlags]::Instance -bor [System.Reflection.BindingFlags]::NonPublic
$method = $type.GetMethod("DisableEventFiring", $flags)
$method.Invoke($receiver, $null)
share|improve this answer
    
Thanks! I`ll try it. –  Alexey Jun 4 '12 at 12:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.