I an trying to activate a feature on site collection. I can activate/deactivate it manually and deactivate via PowerShell but when I try to activate it via PowerShell I get error of object reference.

Disable-SPFeature -identity asd.fgh -URL $SPSite.Url.ToString() -ErrorAction Stop -Confirm:$false  
//works fine

Enable-SPFeature -identity asd.fgh -URL $SPSite.Url.ToString() -ErrorAction Stop -Confirm:$false  
//Error Enable-SPFeature : Object reference not set to an instance of an object.
  • Did you try wrapping the ID in inverted commas? That period may be causing issues. Failing that have you tried the GUID? – Bunzab Jun 2 '17 at 15:43
  • @Bunzab I tried with guid bit no success. Disable works fine without inverted commas. – Saksham Jun 2 '17 at 16:01
  • You will need to check the ULS logs for more details of the exception. If you created the feature does it work from a VS deployment? – Bunzab Jun 3 '17 at 16:07
  • @Bunzab I did not check via VS but it seems that the issue is something else. The same feature activation works fine on another server when I do via PS. Will definitely post the resolution once I find it – Saksham Jun 3 '17 at 19:30
  • Do you have access to the feature activation source code? Sounds a bit like it assumes a SharePoint context which you do not have when running from PowerShell. – Bernd Rickenberg Jun 4 '17 at 12:04

Your Answer

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

Browse other questions tagged or ask your own question.