5

I have an issue trying to get all the installed (not activated) features in SharePoint 2010. I have one site and site collection and what I want to do is have one feature that activates all my features at the site and web scopes. I am trying to get a list of the current installed but not activated features.

SPFeatureDefinitionCollection featureDefinitions = SPContext.Current.Site.FeatureDefinitions;

While using the debugger this returns empty and does not contain any features installed, active, or not active. If I use:

SPContext.Current.Site.Features

It only returns the active features. I was trying to follow this https://stackoverflow.com/questions/5169848/how-to-check-whether-a-feature-has-been-activated but it does not seem to work for me. The scope of the feature containing the code is "Site"

1 Answer 1

9

You can try something like this in powershell.

$allSiteFeatures = Get-SPFeature | Where-Object { $_.Scope -eq "Site" }
$activeFeatures = Get-SPFeature -Site "http://sitecollectionUrl"

$allSiteFeatures | ForEach-Object {
$active = $false
    foreach($feature in $activeFeatures)
    {
      if($feature.Id.ToString() -eq $_.Id.ToString())
      {
         $active = $true
      }
    }
    if(!$active)
    {
       $_.DisplayName
    }
}

If you would like to use c# then SPFarm.FeatureDefinitions should give you a collection of feature definitions which you can filter by scope

2
  • +1 Nice script!
    – Benny Skogberg
    Commented Jul 5, 2013 at 11:28
  • How to get all the farm level features using powershell?
    – samolpp2
    Commented Jun 28, 2017 at 19:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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