locked
SharePoint 2013 - Event Receiver not fire if activate feature thru PowerShell RRS feed

  • Question

  • Hi,

    I am developing an event receiver for document library. This event receiver will capture document's information and store in database during item was added or updated.

    I found that event receiver was not been fired if I activate the feature thru PowerShell or STSADM.exe command.

    Here is the sample script and command I used:

    • Enable-SPFeature –Identity <guid> –url <site url> -force
    • stsadm -o activateeature –Identity <feature name> -url <site url> -force

    Feature is activated, but event receiver not fire.

    And here is my test result:

    1. Deploy thru Visual Studio - working fine
    2. Deploy thru PowerShell and activate feature thru UI - working fine
    3. Deploy thru PowerShell and activate feature thru PowerShell - event receiver not fire
    4. Deploy thru PowerShell and activate feature thru STSADM command - event receiver not fire

    Hope someone here can assist me.

    Thanks!

    Tuesday, June 28, 2016 4:26 AM

Answers

  • Hi,

    Please run the SharePoint 2013 Management Shell  with "Run as administrator" and execute your PowerShell Script.

    Or try to use the PowerShell script below:

    param($siteUrl, $featureName)
    Heading $script:MyInvocation.MyCommand.Name
    $feature = Get-SPFeature $featureName
    if($feature)
    {
    	$featureId = $feature.Id;
    	$site = Get-SPSite $siteUrl
    	if(-not $site.Features[$featureId])
    	{
    		$site.Features.Add($featureId);
    	}
    }
    $site.Dispose() 

    http://mypowershell.webnode.sk/news/activate-feature-with-event-receiver-by-powershell/

    Best Regards,

    Dennis


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    • Proposed as answer by Patrick_Liang Friday, July 1, 2016 9:26 AM
    • Marked as answer by Patrick_Liang Tuesday, July 5, 2016 9:08 AM
    Wednesday, June 29, 2016 9:25 AM

All replies

  • Hi,

    Please check the link below

    https://kmukesh.wordpress.com/2012/03/23/feature-receiver-not-working-when-activating-through-the-powershell-script/


    Please remember to click &#39;Mark as Answer&#39; on the answer if it helps you

    Tuesday, June 28, 2016 4:39 AM
  • Hi Lakshmanan,

    Thanks for your reply. I have tried that, but no luck. 

    Tuesday, June 28, 2016 4:48 AM
  • Hi,

    Please run the SharePoint 2013 Management Shell  with "Run as administrator" and execute your PowerShell Script.

    Or try to use the PowerShell script below:

    param($siteUrl, $featureName)
    Heading $script:MyInvocation.MyCommand.Name
    $feature = Get-SPFeature $featureName
    if($feature)
    {
    	$featureId = $feature.Id;
    	$site = Get-SPSite $siteUrl
    	if(-not $site.Features[$featureId])
    	{
    		$site.Features.Add($featureId);
    	}
    }
    $site.Dispose() 

    http://mypowershell.webnode.sk/news/activate-feature-with-event-receiver-by-powershell/

    Best Regards,

    Dennis


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    • Proposed as answer by Patrick_Liang Friday, July 1, 2016 9:26 AM
    • Marked as answer by Patrick_Liang Tuesday, July 5, 2016 9:08 AM
    Wednesday, June 29, 2016 9:25 AM