Share via


SharePoint 2013: Cleanup or remove missing site and web features from farm

Find missing features

As part of migration process we want to cleanup all unwanted SharePoint solution files from SharePoint farm.

After successful solution retraction, ran below PowerShell cmdlet to find out all missing feature references within content database.

Test-SPContentDatabase -name SharePoint_Content_DB_01 -WebApplication https://SharePoint.poc.com/ | ? { $_.Category -eq "MissingFeature" }

Output:

Category: MissingFeature

Error: True

UpgradeBlocking: False

Message: Database [SharePoint_Content_DB_01] has reference(s) to a missing feature: Id =                  [51592816-393c-4c9f-b6a3-eefba9a65173], Name = [SharePoint2013.Intranet - Web Default Publishing], Description = [], Install Location = [SharePoint2013.Intranet_WebDefaultPublishing].

Remedy: The feature with Id 51592816-393c-4c9f-b6a3-eefba9a65173 is referenced in the database [SharePoint_Content_DB_01], but is not installed on the current farm. The missing feature may cause upgrade to fail. Please install any solution which contains the feature and restart upgrade if necessary.

Locations

We see many missing feature references within content database. Now we need to know the corresponding site or web information of these missing features to cleanup from site or web features collection. Did below steps to get the site or web information of missing features.

  1.  Extract all missing feature ids from Test-SPContentDatabase cmdlet output. Ex: 51592816-393c-4c9f-b6a3-eefba9a65173, 'A6451363-A925-45F1-B256-DABBDBB28BCE

  2.  Log-in to SharePoint SQL Server

  3. Open Sql Server Management studio

  4.  Expand “SharePoint_Content_DB_01” database under databases

  5.  Open new query by selecting “SharePoint_Content_DB_01” database

  6. Run below sql query to get site or web information

    SELECT SiteId, WebId, FeatureId

    FROM [SharePoint_Content_DB_01].[dbo].[Features] WITH (NoLOCK)

    WHERE  FeatureId IN ('51592816-393c-4c9f-b6a3-eefba9a65173', 'A6451363-A925-45F1-B256-DABBDBB28BCE')

  7.  Exectuing sql query generated below output

    Site ID

    Web ID

    Feature ID

    5E29F168-4A71-469E-B3A7-409404ED22AF

    00000000-0000-0000-0000-000000000000

    A6451363-A925-45F1-B256-DABBDBB28BCE

    A0DBD1E3-C516-42BC-B5F9-EA49A89748C2

    6581EFF5-35F1-4973-8304-E3FC48014CE8

    51592816-393C-4C9F-B6A3-EEFBA9A65173

Got the required information of site and web from SQL Server features table and now the next step is to clean up the missing feature references of Site and web.

Clean up or remove missing site feature:

From the above table we see ‘Web ID’ data is having all zeros that means it is a site scope feature.  To clean up or remove missing feature “A6451363-A925-45F1-B256-DABBDBB28BCE” from site scope use below PowerShell commands.

$site = Get-SPSite -Limit All | ? { $_.Id -eq "5E29F168-4A71-469E-B3A7-409404ED22AF" }

$siteFeature = $site.Features["A6451363-A925-45F1-B256-DABBDBB28BCE"]

$site.Features.Remove($siteFeature.DefinitionId, $true)

Clean up or remove missing web feature:

From the above table we see ‘Web ID’ and ‘Site ID’ data so it is a web scrop feature.  To clean up or remove missing feature “51592816-393C-4C9F-B6A3-EEFBA9A65173” from web scope use below PowerShell commands.

$site = Get-SPSite -Limit all | where { $_.Id -eq “A0DBD1E3-C516-42BC-B5F9-EA49A89748C2” } 

$web = $site | Get-SPWeb -Limit all | where { $_.Id -eq "6581EFF5-35F1-4973-8304-E3FC48014CE8"  }

$webFeature = $web.Features["51592816-393C-4C9F-B6A3-EEFBA9A65173"]

$web.Features.Remove($webFeature.DefinitionId, $true)

As part of this removal process, we have experienced below issues.

Error: Exception calling "Remove"

Error:

Exception calling "Remove" with "1" argument(s): "The feature with Id '51592816-393c-4c9f-b6a3-eefba9a65173' is not currently installed. Use 'force' to deactivate it at this scope." At line:1 char:1 + $web.Features.Remove($webFeature.DefinitionId) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : ArgumentException

Solution: Pass true attribute to Features remove method. $web.Features.Remove($webFeature.DefinitionId, $true)

Error: Attempted to perform an unauthorized operation

Error:

Attempted to perform an unauthorized operation. System.UnauthorizedAccessException: Attempted to perform an unauthorized operation. at Microsoft.SharePoint.SPGlobal.HandleUnauthorizedAccessException(UnauthorizedAccessException ex) at Microsoft.SharePoint.SPSecurableObject.CheckPermissions(SPBasePermissions permissionMask) at Microsoft.SharePoint.SPSecurity.ValidateSecurityOnOperation(SPOperationCode code, SPSecurableObject obj) at Microsoft.SharePoint.SPFeatureCollection.Remove(Guid featureId, Boolean force) at CallSite.Target(Closure , CallSite , Object , Object , Boolean )

Solution: we have given myself “Full Control” permissions to the web application in SharePoint central administration.