PowerShell Script To Find Where SharePoint 2010 Features Are Activated

Posted by Brian Jackett on Geeks with Blogs See other posts from Geeks with Blogs or by Brian Jackett
Published on Mon, 02 Jul 2012 06:28:10 GMT Indexed on 2012/07/02 15:16 UTC
Read the original article Hit count: 266

Filed under:

   The script on this post will find where features are activated within your SharePoint 2010 farm.

 

Problem

   Over the past few months I’ve gotten literally dozens of emails, blog comments, or personal requests from people asking “how do I find where a SharePoint feature has been activated?”  I wrote a script to find which features are installed on your farm almost 3 years ago.  There is also the Get-SPFeature PowerShell commandlet in SharePoint 2010.  The problem is that these only tell you if a feature is installed not where they have been activated.  This is especially important to know if you have multiple web applications, site collections, and /or sites.

 

Solution
   The default call (no parameters) for Get-SPFeature will return all features in the farm.  Many of the parameter sets accept filters for specific scopes such as web application, site collection, and site.  If those are supplied then only the enabled / activated features are returned for that filtered scope.  Taking the concept of recursively traversing a SharePoint farm and merging that with calls to Get-SPFeature at all levels of the farm you can find out what features are activated at that level.  Store the results into a variable and you end up with all features that are activated at every level.

   Below is the script I came up with (slight edits for posting on blog).  With no parameters the function lists all features activated at all scopes.  If you provide an Identity parameter you will find where a specific feature is activated.  Note that the display name for a feature you see in the SharePoint UI rarely matches the “internal” display name.  I would recommend using the feature id instead.  You can download a full copy of the script by clicking on the link below.

   Note: This script is not optimized for medium to large farms.  In my testing it took 1-3 minutes to recurse through my demo environment.  This script is provided as-is with no warranty.  Run this in a smaller dev / test environment first.

 

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068

function Get-SPFeatureActivated
{
# see full script for help info, removed for formatting
[CmdletBinding()]
param
(
 
[Parameter(position = 1, valueFromPipeline=$true)]
  [Microsoft.SharePoint.PowerShell.SPFeatureDefinitionPipeBind]
  $Identity
)#end param
  Begin
  {
   
# declare empty array to hold results. Will add custom member `
    # for Url to show where activated at on objects returned from Get-SPFeature.
    $results =
 @()
   
   
$params =
 @{}
  }
 
Process
  {
   
if([string]::IsNullOrEmpty($Identity) -eq $false
)
    {
     
$params = @{Identity = $Identity
            ErrorAction = "SilentlyContinue"
      }
    }
 
   
# check farm features
    $results += (Get-SPFeature -Farm -Limit All @params |
             % {Add-Member -InputObject $_ -MemberType noteproperty
 `
               
-Name Url -Value ([string]::Empty) -PassThru} |
             Select-Object -Property Scope, DisplayName, Id, Url
)

   
# check web application features
    foreach($webApp in (Get-SPWebApplication
))
    {
     
$results += (Get-SPFeature -WebApplication $webApp -Limit All @params |
               % {Add-Member -InputObject $_ -MemberType noteproperty
 `
                 
-Name Url -Value $webApp.Url -PassThru} |
               Select-Object -Property Scope, DisplayName, Id, Url
)

     
# check site collection features in current web app
      foreach($site in ($webApp.
Sites))
      {
       
$results += (Get-SPFeature -Site $site -Limit All @params |
                 % {Add-Member -InputObject $_ -MemberType noteproperty
 `
                   
-Name Url -Value $site.Url -PassThru} |
                 Select-Object -Property Scope, DisplayName, Id, Url
)
                
       
$site.
Dispose()

       
# check site features in current site collection
        foreach($web in ($site.
AllWebs))
        {
         
$results += (Get-SPFeature -Web $web -Limit All @params |
                   % {Add-Member -InputObject $_ -MemberType noteproperty
 `
                     
-Name Url -Value $web.Url -PassThru} |
                   Select-Object -Property Scope, DisplayName, Id, Url
)

         
$web.
Dispose()
        }
      }
    }
  }
 
End
  {
   
$results
  }
} 
#end Get-SPFeatureActivated

 

SPFeatureActivatedOutput1

Snippet of output from Get-SPFeatureActivated

 

Conclusion

   This script has been requested for a long time and I’m glad to finally getting a working “clean” version.  If you find any bugs or issues with the script please let me know.  I’ll be posting this to the TechNet Script Center after some internal review.  Enjoy the script and I hope it helps with your admin / developer needs.

 

      -Frog Out

© Geeks with Blogs or respective owner