2

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

3 Answers 3

3

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

1

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

0

I was running into an issue where I needed to find all of the sites/pages where a web part was in use in SPO.

I wrote this PS script by grabbing code from various examples I found.

Basically, this will loop over all hub sites on our tenant and then any associated sites. THEN it will go over the web parts in use and filter out any that don't match my search criteria.

It's probably not very efficient, but it worked for what I needed.

    #Parameters
#$SiteURL = "https://x.sharepoint.com/sites/HumanResources"
$AdminCenterURL = "https://x-admin.sharepoint.com"
$CSVFile = "C:\Temp\SitePages.csv"
$PagesDataColl = @()

#Connect to SPO
Connect-SPOService -Url $AdminCenterURL 

#Get all Hubsites
$HubSites = Get-SPOHubSite
 
#Get all site collections
$Sites = Get-SPOSite -Limit All 

#Iterate through site collections to get associated sites with the hub
ForEach($Hub in $HubSites)
{ 
    #Get the ID of the Hubsite
    $HubSiteId = $Hub.ID.GUID

    #Iterate through each site collection
    ForEach($Site in $Sites)
    {

        #get the Associated Hubsite ID
        $AssociatedHubSiteID = (Get-SPOSite $site.Url).HubSiteID.GUID
 
        If($AssociatedHubSiteID -eq $HubSiteId)
        {
            #Write-Host "`t $($Site.Url) - $($Site.Title)"

            #Connect to PnP
            Connect-PnPOnline -Url $($Site.Url) -Interactive
        

            #Get All Site Pages
            $SitePages = Get-PnPListItem -List "Site Pages"
 
            
            #Collect Site Pages data
            ForEach($Page in $SitePages)
                {
                    $FileName = $Page.FieldValues.FileRef.Replace($Page.FieldValues.FileDirRef+'/','')
                    $webPage=Get-PnPClientSidePage -Identity $FileName    
                    $webParts = $webPage.Controls
                    foreach($webpart in $webParts) {
                        if ($webpart.Title -ne $null -and $webpart.Title.Contains("xxx"))
                            {
                                $Data = New-Object PSObject -Property ([Ordered] @{
                                    PageName  = $Page.FieldValues.Title
                                    RelativeURL = $Page.FieldValues.FileRef
                                    FilePath = $Page.FieldValues.FileDirRef
                                    FileName = $FileName
                                    CreatedOn = $Page.FieldValues.Created_x0020_Date
                                    ModifiedOn = $Page.FieldValues.Last_x0020_Modified
                                    Editor =  $Page.FieldValues.Editor.Email
                                    ID = $Page.ID
                                })
                                $PagesDataColl += $Data 
                            }

                    }    
       
                }
 
            #$PagesDataColl
 
            #Export data to CSV File
            $PagesDataColl | Export-Csv -Path $CSVFile -NoTypeInformation
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.