Problem Scenario
You are experiencing a bunch of performance issues in SharePoint. After some analysis, you figure out that it is happening due to a specific web part – call it The_Big_BAD_Webpart. How would you find out which sites use this web part?
Solution
Try the following, during non-peak times, especially if your farm is huge and has thousands of sites.
stsadm -o enumallwebs -includewebparts > C:\Temp\EnumeratedOutput.xml
This command might take a while, and can put a lot of load on your database server. That’s why I would strongly recommend running it on non-peak times for your farm.
This EnumeratedOutput.txt will contain a lot of information. You can use the following powershell script to nail down exactly what you need to find out.
For ex. Find out all URLs that contain this text…
$SourceFile="C:\Temp\EnumAllWebsOutput.xml"
$OutputFile="C:\Temp\OnlySiteURL.txt"
$StringToFind="The_Big_BAD_Webpart"
[xml]$SourceFileInMemory = Get-Content $SourceFile
Add-Content $OutputFile "$StringToFind is used in the following sites..."
foreach($AllWebParts in $SourceFileInMemory.databases.database.site.webs.web.WebParts)
{
foreach($WebPart in $AllWebParts.ChildNodes)
{
if($WebPart.Type -eq "$StringToFind")
{
$out = $AllWebParts.ParentNode.Url
Add-Content $OutputFile $out
}
}
}
Or, something like following to get more details…
$SourceFile="C:\Temp\EnumAllWebsOutput.xml"
$OutputFile="C:\Temp\Information.txt"
$StringToFind="The_Big_BAD_Webpart"
[xml]$SourceFileInMemory = Get-Content $SourceFile
Add-Content $OutputFile "$StringToFind is used in the following sites..."
foreach($AllWebParts in $SourceFileInMemory.databases.database.site.webs.web.WebParts)
{
foreach($WebPart in $AllWebParts.ChildNodes)
{
if($WebPart.Type -eq "$StringToFind")
{
$out = "Web id = " + $AllWebParts.ParentNode.id + " " + `
"Site id = " + $AllWebParts.ParentNode.ParentNode.ParentNode.id + " " + `
"Owner = " + $AllWebParts.ParentNode.ParentNode.ParentNode.OwnerLogin + " " + `
$AllWebParts.ParentNode.Url
Add-Content $OutputFile $out
}
}
}
Hope this helps,
Rahul
Quote of the day:
I didn't really say everything I said. - Yogi Berra