I have been tasked with deleting missing features from existing farm. Now there are many articles on this. Here are a few very useful one:
Link 1
Link 2

 

Between the above 2 you will be able to tackle most of the features. Rarely though, you will need a bit extra. And I am thankful to Microsoft as I had to open a ticket to learn this. Sometimes, you will simply not see the feature through the command:
Get-SPFeature Your Feature Id
$db = Get-SPContentDatabase Your Content Database
$features = $db.QueryFeatures([guid]’Your Feature Id’)

Exception calling “QueryFeatures” with “1” argument(s): “Specified argument was out of the range of valid values.
Parameter name: Could not find Feature Your Feature Id.”
At line:3 char:1
+ $features = $db.QueryFeatures([guid]’ Your Feature Id’)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ArgumentOutOfRangeException

This is when we have to a bit of digging into the content and config databases. You will need SQL Server Management Studio for this:


From Config Database:

Use Your Config Database
Go

Select * from SiteMap with (nolock) where databaseid = ‘Your Database Id where the feature is shown as missing’
Carefully check how many sites are in this database seeing the number of rows returned


From Content Database:

Use Your Content Database
Go

Select * from AllSites
Carefully check how many sites are in this database seeing the number of rows returned


Ideally both the above operations are supposed to return the same number of rows (sites actually). But you may find these numbers are somewhat off. Usually it is more in the content database.
When you see the above mismatch, here is how you try to resolve. Create a blank new website. Move the content database to that website. You can do it in Central Admin or can do it via PowerShell.
Once done, try removing the feature from the content database by running Phil Childss’ blog. Essentially by running:
$obj.Features.Remove($feature.DefinitionId, $true)
This time the feature will be found and the removal will be successful.
Once the feature is removed, bring the database back to the original web application.

Advertisements