2

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

3 Answers 3

3

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...

2
  • +1 for being precise! Commented Jan 4, 2011 at 17:04
  • Hi Wictor it worked from the Std PowerShell Console when I changed $Host.Runspace.ThreadOptions from "Default" to "ReuseThread" Thanks Praveen
    – user1739
    Commented Jan 5, 2011 at 2:01
0

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

1
  • SP management shell adds the SharePoint cmdlets as it loads up. Also before running any scripted deployment make sure that you have the necessary permissions assigning your user Shell admin role: Add-SPShellAdmin [-UserName] <String> [-database <SPDatabasePipeBind>] . Read more on my blog andersrask.spoint.me/2010/09/26/… Commented Dec 21, 2010 at 7:39
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.