Finding Sites with a Particular Feature Activated

February 12th, 2011

I continually have a question arise that seems easy to answer, yet from what I can tell, is not yet available with SharePoint out-of-the-box in its user interfaces. That question is:

What are all of the sites with feature xyz enabled?

A few years ago with a MOSS 2007 client environment where I had to answer this question, I was left with writing a quick C# console application that would crawl a web application for me and discover all of the site collections with a particular feature enabled. Not quite the best way of doing things, but it’s what was the best at the time.

Fast forward to SharePoint 2010. Now, PowerShell is in the mix and required for all SharePoint installations. Thanks Microsoft! So now, I have the vast capabilities of PowerShell available on any SharePoint farm I may encounter on any client environment with which I may be working. Plus, there’s an added bonus that, for some reason, the word “script” seems to scare clients and IT departments less than “console applications”. Even though PowerShell scripting can often wield the same powers as a C# console application, it seems to be accepted with more ease which makes my life easier.

Now that PowerShell is widely available, I rewrote that “quick C# console application” I referenced above in PowerShell for use recently on a SharePoint 2010 environment. The script below has a slightly more specific task than solving the question I posed above:

Output all of the site collection URLs within a particular web application that have a particular site-scoped feature enabled.

Here’s my script to do just such a task. The code below is meant for a single ps1 file.

Please note that it should work with both the 2007 & 2010 SharePoint product lines: SharePoint 2010 (Foundation & Server), WSS 3.0, and MOSS 2007. I have only tested this code on a SharePoint Server 2010 environment, but have no reason to believe it wouldn’t work in the other environments.

Feel free to use this script or modify it to fit your needs. There are several extra features that could be added to this script to make it even more versatile:

  • Reporting on the status of multiple features, not just a single feature
  • Reporting based on feature name versus feature GUID
  • Reporting on features scoped at different levels besides Site
    • Farm
    • Web Application
    • Web
  • Crawling other scopes besides a single web application
    • The entire farm,
    • Multiple web applications,
    • A subset of site collections,
    • A subset of sites,
    • Based on another block of script and/or function call to determine if a site should be scanned by the script,
    • etc.

I think the above script is a great starting point. Hopefully either myself or someone will get around to adding the above suggestions. Please share in the comments if you do end up extending this script!

Tags: , , , , , , , ,

8 Responses to “Finding Sites with a Particular Feature Activated”

  1. Mark Marquis Says:

    Good writeup Steve….I have been looking for similar script just recently

  2. dot commandante Says:

    try catch is not supported in PS 1.0,guid,c3f862ff-b496-437d-925f-25c5f90ad482.aspx

  3. Steve Mayes Says:

    Thanks – excellent point dot commandante! See the article in the link for those needing to adapt this script to PowerShell v1.

  4. SPAdmin Says:

    Newbie to Powershell. We have a publishing website and lots of sub sites.
    I am running this script but it is not displaying any sub sites below the root site.

    We have a third party feature and by using get-spfeature I have the third party ID

    .\sites.ps1 “http://XYZ/” “00bfea71-ec85-4903-972d-ebe475780106”

    All I get is

    “All site collections in http://XYZ/ that have the feature 00bfea71-ec85-4903-972d-ebe475780106 activated:”

    We need to see all sub sites that have this feature turned on.



  5. Steve Mayes Says:

    Hi SPAdmin,

    The script I supplied above works only for site collection feature – also known as site-scoped features. From your description, my guess is that you have a web-scoped feature and want to determine all of the sub sites where that feature is active.

    The script above would need to be modified to iterate through all of the webs within each site collection. It was listed in the original post as one of the desired modifications that one could make starting with the script above. If you are using MOSS 2007, you’ll need to add a second loop to cover each web within each site collection.

    If you are using SharePoint 2010, check out the QueryFeatures method of either the SPWebApplication (can be obtained using Get-SPWebApplication ) or SPContentDatabase (Get-SPContentDatabase ) classes. This method is very powerful, very quick, and performs the same work as my script above for features of any scope. I am hoping to post on this shortly and will update this original post if I do!

    Best of luck,

  6. RMR Says:

    Hi thereb Steve,
    Good code man. That’s exactly what I have been looking for, but it’s not working.
    I tried to test it in ShP 2010 and I am getting this message after your message saying “All site collections in $($webAppUrl) that have the feature $($featureId) activated:”:

    cmdlet ForEach-Object at command pipeline position 1
    Supply values for the following parameters:

    Any idea of what it’s going on?

  7. Steve Mayes Says:

    Hi RMR,

    Did you make sure that the opening curly brace was on the same line as the ForEach-Object cmdlet – as shown in the script? I’ve seen that error before if the curly brace is not on the same line. That is because PowerShell assumes that, without a brace, there have simply been no parameters included and thus requests a parameter per your message above.

    Let me know if this helps!

    Best of luck,

  8. Muhammad Zeeshan Tahir Says:


    I am unable to run it using powershell. I put all the code in .ps1 file and ran using .\GetAllSitesWithFeatureActivated.ps1 “https://mywebappurl” “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx” but its throwing the error below.

    Exception calling “Lookup” with “1” argument(s): “Value cannot be null.
    Parameter name: requestUri”
    At E:\GetAllSitesWithFeatureActivated.ps1:23 char:73
    + $webApp = [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup <<<<
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

    Kindly suggest.


Leave a Reply