Question

In SP 2013 OnPrem, how can I track if a web part is being used or not?

And, if it is being used, how can I list all pages using those web parts?

We will migrate all structure and content to SharePoint Online using ShareGate. In Site Settings -> Web Parts I can see a list of 40 Web Parts and 9 of them are 3rd party Web Parts from a company called SPMeta2.

Before we go trying to find out how to migrate them, I would like to know if they are really being used and where. How can I track this info?

Thanks

Was it helpful?

Solution

One way you can do it, go to the one of the web parts page and at top page query string add ?contents=1 , then you will get 'web parts maintenance page' where you can see all web parts on that page,with the type, open or closed. If the web parts are closed, then those are not used.

The above manual process you can automate it using the PowerShell script, loop through all web part pages like above and check out the type whether open or closed.

Find All Web Parts in Use in a SharePoint Site using PowerShell

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration parameters
$SiteURL = "http://intranet.crescent.com"
$ReportOutput="C:\Webparts-in-use.csv"

$ResultCollection = @()

#Get All Subsites in a site collection and iterate through each
$Site = Get-SPSite $SiteURL
ForEach($Web in $Site.AllWebs)
{
    write-host Processing $Web.URL
    # If the Current Web is Publishing Web
    if ([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($Web))
    {
        #Get the Publishing Web
        $PubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($Web)

        #Get the Pages Library
        $PagesLib = $PubWeb.PagesList
     }
     else
     {
        $PagesLib = $Web.Lists["Site Pages"]
     }            
        #Iterate through all Pages 
        foreach ($Page in $PagesLib.Items | Where-Object {$_.Name -match ".aspx"})
        {
            $PageURL=$web.site.Url+"/"+$Page.File.URL
            $WebPartManager = $Page.File.GetLimitedWebPartManager([System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)

            #Get All Web Parts data
            foreach ($WebPart in $WebPartManager.WebParts)
            {
                $Result = New-Object PSObject
                $Result | Add-Member -type NoteProperty -name "Site URL" -value $web.Url
                $Result | Add-Member -type NoteProperty -name "Page URL" -value $PageURL
                $Result | Add-Member -type NoteProperty -name "Web Part Title" -value $WebPart.Title
                $Result | Add-Member -type NoteProperty -name "Web Part Type" -value $WebPart.GetType().ToString()

                $ResultCollection += $Result
            }
        }
}
#Export results to CSV
$ResultCollection | Export-csv $ReportOutput -notypeinformation

Source:

Find All Web Parts in Use in a SharePoint Site using PowerShell

OTHER TIPS

I did a sample script to phrase DOM content from application page(yourpage?contents=1) which might help you for PowerShell automation.

$root = $url+'/_layouts/15/ManageCheckedOutFiles.aspx?List={'+$listID+'}'
Write-Host $root

$result = Invoke-WebRequest $root -Method Get -WebSession $webSession
//replace the logic to yours to phrase DOM, keep it as reference
$table = $result.ParsedHtml.IHTMLDocument3_getElementById("onetidTable")
$trs=$table.getElementsByTagName('tr')
for($i=1;$i -lt $trs.length;$i++){
    $tr =  $trs[$i];
    $check=$tr.GetElementsByClassName('ms-standardheader')

original thread if you have interest

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top