Question

I have a problem where I can enable a feature from the UI and code in FeatureActivated method works as expected. However, if I try to enable the feature via powershell as a scripted deployment, the feature is activated but the code in FeatureActivated method is not executed.

I am running the Powershell as Admin.

Has anyone come across this issue before?

Praveen

Was it helpful?

Solution

Looks like you have some kind of threading issue here. Standard PowerShell runs each pipeline/line on different threads while the SharePoint PowerShell console runs all in the same thread. Try starting a std PowerShell console and write

$Host.Runspace.ThreadOptions = "ReuseThread"

And then run your script again and report back.

Also make sure that you do not have any references to SPContext in your receivers...

OTHER TIPS

I got this working now.

The code in FeatureActivated was not executing when I used the General PowerShell command window even when running with Admin rights.

However, the code executed fine when I used “SharePoint 2010 Management Shell”.

Praveen

Use Sharepoint Management shell to run Powershell scripts. We have faced the same issue and got the solution by using Sharepoint Management shell which automatically adds Microsoft.Sharepoint.Powershell dll as reference.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top