I had a situation come up where I need to figure out where, in a web application containing several webs and site collections, a specific feature was activated. I developed the following PowerShell script to help automate the process and display exactly where a specific feature is activate. Simply pass it the url of the web application you wish to look in, as well as the id of your feature. The script will automatically determine if your feature is scoped at the site collection or at the web level and will print out on screen a list of all site collections or webs where it is activated. Enjoy!
$myFeature = Get-SPFeature $featureId
if($myFeature.Scope -eq “Site”)
{
foreach($siteCollection in $spApp.Sites)
{
foreach($featureRef in $siteCollection.Features)
{
$curFeature = Get-SPFeature $featureRef.DefinitionId
if($curFeature -eq $myFeature)
{
write-host “Found at site collection:” $siteCollection.Url -ForegroundColor green
}
}
$siteCollection.Dispose()
}
}
else
{
foreach($siteCollection in $spApp.Sites)
{
foreach($web in $siteCollection.AllWebs)
{
foreach($featureRef in $web.Features)
{
$curFeature = Get-SPFeature $featureRef.DefinitionId
if($curFeature -eq $myFeature)
{
write-host “Found at Web:” $web.Url -ForegroundColor green
}
}
$web.Dispose()
}
$siteCollection.Dispose()
}
}
|