Wednesday, March 12, 2014

SharePoint Web Part Usage Report - Find All Locations where a Particular web part is being Used

During Migration, I had to get the URLs where a particular web part is being used. So, Used this PowerShell script to generate SharePoint web part usage report.

This script made compatible with SharePoint 2007, So it can be used in SharePoint 2010 and in SharePoint 2013 as well. Just change the Web Application URL from "" to yours.

SharePoint Web Part Usage Report using PowerShell:

Function global:Get-SPWebApplication($WebAppURL)
 return [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($WebAppURL)

#Get-SPSite cmdlet for MOSS 2007
function global:Get-SPSite($url)
    return new-Object Microsoft.SharePoint.SPSite($url)

Function global:Get-SPWeb($url)
  $site= New-Object Microsoft.SharePoint.SPSite($url)
        if($site -ne $null)
    return $web
#Write Header to CSV File
"Page URL,  Web Part Name" | out-file "D:\Data\ExcelServicesWPs.csv"
#Get all Webs
$WebApp = Get-SPWebApplication "" 
foreach($site in $WebApp.Sites)
#Iterate through webs
foreach ($web in $site.AllWebs)
#Get All Pages from site's Root into $AllPages Array
$AllPages = @($web.Files | Where-Object {$_.Name -match ".aspx"})
#Search All Folders for Pages
foreach ($folder in $web.Folders)
       #Add the pages to $AllPages Array
       $AllPages += @($folder.Files | Where-Object {$_.Name -match ".aspx"})
 #Iterate through all pages
 foreach($Page in $AllPages)
     $webPartManager = $web.GetLimitedWebPartManager($Page.ServerRelativeUrl, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
     # Array to Hold Closed Web Parts
                foreach ($webPart in $webPartManager.WebParts | Where-Object {$_ -like "*Excel*"})
                 $result = "$($$($Page.ServerRelativeUrl), $($webpart.Title)"
                 Write-Host "Web Part Found at: "$result
                 $result | Out-File "D:\Data\ExcelServicesWPs.csv" -Append
The above script scans all libraries (not just "Site Pages" or "Pages" library! What if a web part page stored in a "documents" library?) from all sites where a particular webpart is being used and generates report in CSV format.

But if you want to scan only publishing pages, Here is how the script goes:
 $PublishingWeb =  [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
        $PagesLib = $PublishingWeb.GetPublishingPages()
        foreach($Page in $PagesLib)

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...