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

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

share|improve this question

3 Answers 3

up vote 3 down vote accepted

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

share|improve this answer
    
+1 for being precise! –  Falak Mahmood Jan 4 '11 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 Jan 5 '11 at 2:01

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

share|improve this answer
    
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/… –  Anders Rask Dec 21 '10 at 7:39

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.

share|improve this answer

Your Answer

 
discard

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