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

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

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

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy