Test-SPContentDatabase: Fix MissingWebPart Issue in SharePoint 2013 Migration

Problem: MissingWebPart Issues when running Test-SPContentDatabase cmdlet on SharePoint content database during SharePoint 2013 migration project.
Category                : MissingWebPart
Error                      : True
UpgradeBlocking  : False
Message                : WebPart class [9a43cf43-4500-d748-6385-09e622f28c01] is referenced [3] times in the database [WSS_Content_Database], but is not installed on the current farm. Please install any feature/solution which contains this web part.
Remedy                 : One or more web parts are referenced in the database [WSS_Content_Database], but are not installed on the current farm. Please install any feature or solution which contains these web parts.

sharepoint 2013 test-spcontentdatabase missingwebpart

Root cause: MissingWebPart issue is because the migrated SharePoint 2013 sites contain references to custom Web Parts that are not installed in the
target Farm.

Solution:

Install & deploy the solution package (WSP), which contains the web part, to your new SharePoint 2013 farm to fix this issue! Well, that wouldn’t be the case always. What if you don’t need the web part anymore in your SharePoint and want to get rid of it?

Find all pages referring the Web Part using PowerShell:

Use this PowerShell script to find all pages using the particular web part in your environment.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

Function Run-SQLScript($SQLServer, $SQLDatabase, $SQLQuery)
{
    $ConnectionString = "Server =" + $SQLServer + "; Database =" + $SQLDatabase + "; Integrated Security = True"
    $Connection = new-object system.data.SqlClient.SQLConnection($ConnectionString)
    $Command = new-object system.data.sqlclient.sqlcommand($SQLQuery,$Connection)
    $Connection.Open()
    $Adapter = New-Object System.Data.sqlclient.sqlDataAdapter $Command
    $Dataset = New-Object System.Data.DataSet
    $Adapter.Fill($Dataset) 
    $Connection.Close()
    $Dataset.Tables[0]
}

#Define configuration parameters
$Database="WSS_Content_KM"
$webPartID="90F70A36-4EC6-167D-792C-31B7EA83201B"

#Get the Database Server from Database
$server = (Get-SPDatabase |?{ $_.name -eq $Database}).server

#Query SQL Server content Database to get information about the MissingFiles
$Query = "SELECT distinct ID,SiteId,DirName, LeafName, WebId, ListId from dbo.AllDocs where id in (select tp_PageUrlID from dbo.AllWebParts where tp_WebPartTypeId ='$($webPartID)')"
$QueryResults = Run-SQLScript -SQLServer $Server -SQLDatabase $Database -SQLQuery $Query | select Id , SiteId, DirName, LeafName, WebId, ListId 

#Iterate through results
foreach ($Result in $QueryResults)
{
    if($Result.id -ne $Null)
    {
        $Site = Get-SPSite -Limit all | where { $_.Id -eq $Result.SiteId }
        $Web = $Site | Get-SPWeb -Limit all | where { $_.Id -eq $Result.WebId }

        #Get the URL of the file which is referring the web part
        $File = $web.GetFile([Guid]$Result.Id)
        write-host "$($Web.URL)/$($File.Url)" -foregroundcolor green
    }
}

This script gets you the list of pages where the missing web part is being referenced from.

How to Delete Web Part from SharePoint Page? 

So you decided that the web part is no longer necessary and want to remove the web part from the page? Well:

  • Get into WebPart Maintenance page by appending the query string “?contents=1” to the URL
  • In the web part maintenance page, Select and delete the unwanted web part!

How about removing a web part from the entire site collection or web application rather one by one? Well, PowerShell is your friend! Here is the PowerShell script to remove a web part from the SharePoint site collection: Remove a web part from page using PowerShell in SharePoint.

Remember, as Microsoft says, even reading from SharePoint content databases isn’t supported. Use this PowerShell script to get all locations where a particular web part is being used. PowerShell to find the web part’s usage in SharePoint

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

2 thoughts on “Test-SPContentDatabase: Fix MissingWebPart Issue in SharePoint 2013 Migration

  • thank you for the script
    replace the $Server=”Ab-SQL-001″ with $server = (Get-SPDatabase |?{ $_.name -eq $Database}).server

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *