Office 365: Exception while Activation Site Level Publishing Feature “SharePoint Server Publishing Infrastructure”

Hi All,

One of our requirements is to activate the publishing feature (“SharePoint Server Publishing Infrastructure”) on our one of the SharePoint online site collection which is of type Team site.

So we have CSOM + PowerShell approach and used following CSOM code to activate the features using PowerShell script.

  1. #getting all site features  
  2. $siteFeatures = $clientContext.Site.Features   
  3. $clientContext.Load($siteFeatures)  
  4. $clientContext.ExecuteQuery()  
  6. #activating “SharePoint Server Publishing Infrastructure” feature  
  8. $featureId = “f6924d36-2fa8-4f0b-b16d-06b7250180fa”  
  9. $fId = [GUID]$featureId  
  10. $siteFeatures.Add($fId, $true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::Site)  
  11. $clientContext.ExecuteQuery()  
As soon as above code executed we got the following error.

An error occurred activating Feature. Error detail: Exception calling "ExecuteQuery" with "0" argument(s): "Feature with Id 'f6924d36-2fa8-4f0b-b16d-06b7250180fa' is not installed in this farm, and cannot be added to this scope.”

After digging a lot and went through couple of blogs, noticed that, in some blogs FeatureDefinitionScope is set to None. We tried this option and it worked like charm.

So it looks like as,
  1. $siteFeatures.Add($fId, $true,   
  2. [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None)  
For now I am not sure is this bug or it works in this way but I really wondered why so this since there are 4 scopes in FeatureDefinitionScope enumeration as :
  1. using System;  
  2. namespace Microsoft.SharePoint.Client  
  3. {      
  4.     public enum FeatureDefinitionScope   
  5.    {      
  6.         None,        
  7.         Farm,         
  8.         Site,         
  9.         Web     
  10.      }  
  11. }  
I then tried with the web level feature but same error and then it worked with None option.


While activating feature using CSOM it doesn’t accept respective scope (Site or Web), we need to provide feature definition scope as None.



Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now