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 want to activate a custom feature with PowerShell on a few sites in my environment.

When I´m doing this job over the GUI, everything is perfect.

But when I´, doing it with my script, the feature is activate in the feature list, but nothing happens.

  • Why is the GUI and script activation different?
  • How can I fix my script?

Thank you in advance!

My code snippet:

Enable-SPFeature FeatureID -Url https://test-portal.sharepoint.de/ -ErrorAction Stop

also not working

Enable-SPFeature -Identity "FeatureName" -Url https://test-portal.sharepoint.de/ -ErrorAction Stop
share|improve this question
1  
These weird errors usually happen for me when PS is caching old versions of files (esp. wsps). I guess you've tried to restart PowerShell? –  tarjeieo May 8 '12 at 13:21
    
Sure :-( This can´t be the reason for my problem –  LaPhi May 8 '12 at 17:13
    
What does your feature do? Custom code in activation event receiver? –  tarjeieo May 9 '12 at 6:33
add comment

3 Answers 3

Usually this happens if you have feature activated event receiver and use http context in code somehow (accessing to SPContext.Current or creating web part, that might use internally Http context). When you activate your feature through UI, Http context is not null and all may work as expected, but when activating through PS or stsadm Http context is null and this may lead to unexpected behavior.

share|improve this answer
add comment

Is your feature assembly GACed? If not, make sure the feature assembly is located someplace where powershell can find it.

share|improve this answer
add comment

If your code references something that only the IIS worker process can see (like web.config) it might fail. PowerShell's execution environment is different than the running web application.

share|improve this answer
    
The OP is asking about an OOTB SP cmdlet, there is no custom code here. –  RJ Cuthbertson Oct 4 '12 at 17:41
    
Custom code most certainly CAN run during a cmdlt like Enable-SPFeature. There are event receivers specifically made to allow solution developers the opportunity to do something during install, upgrade and activation. Check MSDN. –  ArbutusJoe Dec 14 '12 at 17:05
    
That's not what I was asserting. I was questioning the relevancy of your answer to the OP. –  RJ Cuthbertson Dec 14 '12 at 23:35
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.