Geeks With Blogs


Steve Clements .Net and then some....

It’s not an uncommon task to want to find out in what webs you have a specific feature enabled.  This little script does just that, taking 2 params (site collection url, feature name) and simple output the SharePoint web url.  Nothing fancy, but certainly a useful script to have in your toolbox!

A good example of this is where you are using content publishing going from an Enterprise internal farm to a Foundation external farm, certain feature won’t be in the Foundation farm and will cause the Content Publisher to fail, it will be so kind as to tell you what feature is causing the problem, but not where it is!  Someone somewhere has enabled a feature they shouldn’t have!!!

I’m sure some “one line wizards” could optimise this script – but that’s not my bag – I’m interested in getting the job done for our clients and providing a useful script we can use again and again.

You could of course add in Disable-SPFeature command if you wanted to do that at the same time…

Feature Finder script
  1. #Powershell script to identify where in a site collection a specific feature is enabled
  2. #Version: 1.0
  3. #Author: Steve Clements | Perspicuity Ltd
  4. #Params:
  5. #$siteCollectionUrl - url of the site collection
  6. #$featureName - name of the feature you want to find
  9. param ([string] $siteCollectionUrl, [string] $featureName)
  11. if(!$siteCollectionUrl -or !$featureName) {
  12.     Write-Host -ForegroundColor Red "You must provide a site collection url and feature name to find!"
  13.     break
  14. }
  16. Write-Host -BackgroundColor DarkGreen "Feature '"$featureName "' exists in these sites"
  18. Get-SPSite $siteCollectionUrl | ForEach-Object {
  19.     Get-SPWeb -Site $_ | ForEach-Object {
  20.       $f = Get-SPFeature -Web $_ | Where {$_.DisplayName -eq $featureName}
  21.       if($f) {
  22.           Write-Host $_.Url
  23.       }
  24.     }
  25. }
  27. Write-Host -BackgroundColor DarkGreen "Done"
Posted on Friday, March 9, 2012 3:21 PM Sharepoint , PowerShell | Back to top

Comments on this post: PowerShell script to find where in a site collection a specific feature is enabled.

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Steve Clements | Powered by: