Home Contact

The Frog Pond of Technology

Ripples of Knowledge for SharePoint and Other .Net Technologies

News

 Subscribe to this blog


About Me

Name:
Brian T. Jackett
Location:
Columbus, OH
Company:
Microsoft

Find me on...

Tag Cloud


Archives

Post Categories

Syndication:

PowerShell Script To Find Where SharePoint 2010 Features Are Activated

   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


Monday, July 2, 2012 8:28 AM

Feedback

# re: PowerShell Script To Find Where SharePoint 2010 Features Are Activated

Brian, great script, just what I was looking for. One thing only - in my case, values in the Url and Id columns of the output are beeing truncated to contain 30 characters, is it something to do with my settings somewhere? What would they be?
Thanks. 7/18/2012 11:36 PM | Elena

# re: PowerShell Script To Find Where SharePoint 2010 Features Are Activated

Elena,

The output will attempt to display in a tabular fashion within the limits of your PowerShell window. You can output to a file (txt, CSV, etc.) or pipe to Format-List and that should remedy truncation of data issue.
7/21/2012 4:24 PM | Brian T. Jackett

# re: PowerShell Script To Find Where SharePoint 2010 Features Are Activated

This looks like a interessting project for the holidays. Thanks 12/24/2012 4:27 PM | Jana

# re: PowerShell Script To Find Where SharePoint 2010 Features Are Activated

Brian,

Did you every have a chance to write the same script that would work with SharePoint 2007? 1/15/2013 9:20 AM | Terry

# re: PowerShell Script To Find Where SharePoint 2010 Features Are Activated

Terry,

Yes, a few posts later I posted a 2007 compatible script. Caution I did find some issues where that script reported different results when I ran it against a 2010 farm. Not sure why the inconsistencies but it may have been due to custom site templates or definitions. Let me know if you have any issues.
1/15/2013 9:44 AM | Brian T. Jackett

# re: PowerShell Script To Find Where SharePoint 2010 Features Are Activated

If I wanted to just search for a particular feature. Would I just remove the -limit all and replace it with -identity "name of feature" in each section. I'm not a developer :( although i grasp the over all intent. I just am not sure where I should input a specific feature identity to get specific results.
3/13/2013 11:15 AM | Jan

# re: PowerShell Script To Find Where SharePoint 2010 Features Are Activated

Jan,

You can run my custom function Get-SPFeatureActivated with the -identity parameter and supply the name of the feature. Unfortunately you will need to know the underlying name of the feature, not necessarily the display you see in the web browser.

Ex. Get-SPFeatureActivated -identity "PublishingSite"
3/13/2013 11:46 AM | Brian T. Jackett

# re: PowerShell Script To Find Where SharePoint 2010 Features Are Activated

Quick response! Thank you because I feel I"m over here destroying your code with my "what if I do this" approach. lol
I tried using Get-SPFeatureActivated -Identity "Basic Web Parts" at the very top of the function (if this is where I should put it) and I received the error Missing functionbody in function declaration. Again please excuse my lack of development prowess. 3/13/2013 12:08 PM | Jan

# re: PowerShell Script To Find Where SharePoint 2010 Features Are Activated

Jan,

You'll need to put that function execution call at the bottom of the script after the function has been declared. The other thing to do is ensure the "Basic Web Parts" name is correct. If you run the function by itself (just Get-SPFeatureActivated at the end of script) and then look through the output for that feature double check the name is correct. My bet is that it will actually have no spaces or be slightly different. Give that a try and see if it helps.
3/15/2013 8:51 AM | Brian T. Jackett

# re: PowerShell Script To Find Where SharePoint 2010 Features Are Activated

Well...I ran the script by itself and also tried adding the identity at the bottom of the function:
} #end Get-SPFeatureActivated -identity "internalnamehere" and nothing. As soon as I hit enter it goes straight to the command prompt. Either way it hates me.lol I know this is something I"m doing and I'm winning the doh! award right now. 4/15/2013 12:06 PM | Jan

# re: PowerShell Script To Find Where SharePoint 2010 Features Are Activated

Jan,

The last line for "#end Get-SPFeatureActivated" is a comment (designated by the # symbol) and is not actually executed. You'll need to call "Get-SPFeatureActivated -Identity nameOfYourFeature" by itself.
5/1/2013 2:46 PM | Brian T. Jackett

# re: PowerShell Script To Find Where SharePoint 2010 Features Are Activated

Hello,

How can i pass custom parameters like web application URL and GUID of the feature that i want to search that web application?

Regards
5/19/2014 10:16 AM | Muhammad Zeeshan Tahir

# re: PowerShell Script To Find Where SharePoint 2010 Features Are Activated

I Tried exporting to a csv file it get error. can you please let me know if i am doing correct

Get-SPFeatureActivated | Export-Csv c:\temp\featurs.csv 6/5/2014 11:21 AM | santosh kumar

Post A Comment
Title:
Name:
Email:
Comment:
Verification: