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 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 http://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"

share|improve this question

1 Answer 1

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

share|improve this answer
    
+1 Nice script! –  Benny Skogberg MCSA Jul 5 '13 at 11:28

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.