Activate feature with Event receiver by Powershell

21/11/2013 14:20

#There is a problem with Enable-SPFeature command in case of having event receiver in the feature. Feature Activated event is not fired. This is used as workaroud..

#inspired by https://social.msdn.microsoft.com/Forums/sharepoint/en-US/bd9a562e-eeb8-4fd3-a37d-3dc736ff6b56/programmatically-activating-and-deactivating-a-feature

#Activate Site Feature with Event Receiver

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()