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.
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
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
Originally posted on: https://briantjackett.com/archive/2012/07/02/powershell-script-to-find-where-sharepoint-2010-features-are-activated.aspx#616717Brian, 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.
LikeLike
Originally posted on: https://briantjackett.com/archive/2012/07/02/powershell-script-to-find-where-sharepoint-2010-features-are-activated.aspx#616809Elena,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.
LikeLike
Originally posted on: https://briantjackett.com/archive/2012/07/02/powershell-script-to-find-where-sharepoint-2010-features-are-activated.aspx#623042This looks like a interessting project for the holidays. Thanks
LikeLike
Originally posted on: https://briantjackett.com/archive/2012/07/02/powershell-script-to-find-where-sharepoint-2010-features-are-activated.aspx#623877Brian,Did you every have a chance to write the same script that would work with SharePoint 2007?
LikeLike
Originally posted on: https://briantjackett.com/archive/2012/07/02/powershell-script-to-find-where-sharepoint-2010-features-are-activated.aspx#623880Terry,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.
LikeLike
Originally posted on: https://briantjackett.com/archive/2012/07/02/powershell-script-to-find-where-sharepoint-2010-features-are-activated.aspx#626027If 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.
LikeLike
Originally posted on: https://briantjackett.com/archive/2012/07/02/powershell-script-to-find-where-sharepoint-2010-features-are-activated.aspx#626033Jan,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”
LikeLike
Originally posted on: https://briantjackett.com/archive/2012/07/02/powershell-script-to-find-where-sharepoint-2010-features-are-activated.aspx#626035Quick response! Thank you because I feel I”m over here destroying your code with my “what if I do this” approach. lolI 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.
LikeLike
Originally posted on: https://briantjackett.com/archive/2012/07/02/powershell-script-to-find-where-sharepoint-2010-features-are-activated.aspx#626094Jan,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.
LikeLike
Originally posted on: https://briantjackett.com/archive/2012/07/02/powershell-script-to-find-where-sharepoint-2010-features-are-activated.aspx#627906Well…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.
LikeLike
Originally posted on: https://briantjackett.com/archive/2012/07/02/powershell-script-to-find-where-sharepoint-2010-features-are-activated.aspx#628365Jan,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.
LikeLike
Originally posted on: https://briantjackett.com/archive/2012/07/02/powershell-script-to-find-where-sharepoint-2010-features-are-activated.aspx#637779Hello,How can i pass custom parameters like web application URL and GUID of the feature that i want to search that web application?Regards
LikeLike
Originally posted on: https://briantjackett.com/archive/2012/07/02/powershell-script-to-find-where-sharepoint-2010-features-are-activated.aspx#638201I Tried exporting to a csv file it get error. can you please let me know if i am doing correctGet-SPFeatureActivated | Export-Csv c:tempfeaturs.csv
LikeLike
Originally posted on: https://briantjackett.com/archive/2012/07/02/powershell-script-to-find-where-sharepoint-2010-features-are-activated.aspx#639491sorry, I am a complete dummy but how do you get the output of this? I tried with Write-Host with no luck.
LikeLike
Originally posted on: https://briantjackett.com/archive/2012/07/02/powershell-script-to-find-where-sharepoint-2010-features-are-activated.aspx#640581I’m sure I’m missing the obvious, but a cut-n-paste of the above script, and execution of it gets me “Missing expression after unary operator ‘-‘.”
LikeLike
Originally posted on: https://briantjackett.com/archive/2012/07/02/powershell-script-to-find-where-sharepoint-2010-features-are-activated.aspx#644040space being present after the backtick (`) Should be like this: $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)
LikeLike
Originally posted on: https://briantjackett.com/archive/2012/07/02/powershell-script-to-find-where-sharepoint-2010-features-are-activated.aspx#648671Hi,I’m trying to run this script and getting the following error. I get this error with or without the identity parameter being passed. Any help to resolve this is much appreciated.Get-SPFeatureActivated : Exception has been thrown by the target of an invocation.At line:82 char:23+ Get-SPFeatureActivated <<<< + CategoryInfo : NotSpecified: (:) [Get-SPFeatureActivated], TargetInvocationException + FullyQualifiedErrorId : System.Reflection.TargetInvocationException,Get-SPFeatureActivated
LikeLike