Sunday, January 17, 2016

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 contains references to custom Web Parts which are not installed in the target Farm.

Solution:
Install & deploy the solution package (WSP) which contains the webpart to your new SharePoint 2013 farm to fix this issue! Well, that wouldn't be a case always, What if you don't really need the webpart anymore in your SharePoint and want to get rid it?

Find all pages referring the Web Part using PowerShell:
Use this PowerShell script to find all pages which are 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
$Server="Ab-SQL-001"
$Database="WSS_Content_KM_New"
$webPartID="90F70A36-4EC6-167D-792C-31B7EA83201B"

#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 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 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



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


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...