Created
December 22, 2014 05:44
-
-
Save wpsmith/ad57a1c78551be9c12b6 to your computer and use it in GitHub Desktop.
PowerShell: Properly remove a SharePoint Feature from the Content DB. Example Warning: [MissingFeature] Database [SharePoint_Content_Portal] has reference(s) to a missing feature: Id = [8096285f-1463-42c7-82b7-f745e5bacf29], Name = [My Feature], Description = [], Install Location = [Test-MyFeature]. The feature with Id 8096285f-1463-42c7-82b7-f7…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Remove-SPFeatureFromContentDB($ContentDb, $FeatureId, [switch]$ReportOnly) | |
{ | |
$db = Get-SPDatabase | where { $_.Name -eq $ContentDb } | |
[bool]$report = $false | |
if ($ReportOnly) { $report = $true } | |
$db.Sites | ForEach-Object { | |
Remove-SPFeature -obj $_ -objName "site collection" -featId $FeatureId -report $report | |
$_ | Get-SPWeb -Limit all | ForEach-Object { | |
Remove-SPFeature -obj $_ -objName "site" -featId $FeatureId -report $report | |
} | |
} | |
} | |
function Remove-SPFeature($obj, $objName, $featId, [bool]$report) | |
{ | |
$feature = $obj.Features[$featId] | |
if ($feature -ne $null) { | |
if ($report) { | |
write-host "Feature found in" $objName ":" $obj.Url -foregroundcolor Red | |
} | |
else | |
{ | |
try { | |
$obj.Features.Remove($feature.DefinitionId, $true) | |
write-host "Feature successfully removed from" $objName ":" $obj.Url -foregroundcolor Red | |
} | |
catch { | |
write-host "There has been an error trying to remove the feature:" $_ | |
} | |
} | |
} | |
else { | |
#write-host "Feature ID specified does not exist in" $objName ":" $obj.Url | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Remove-SPFeatureFromContentDB -ContentDB "SharePoint_Content_Portal" -FeatureId "8096285f-1463-42c7-82b7-f745e5bacf29" –ReportOnly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Remove-SPFeatureFromContentDB -ContentDB "SharePoint_Content_Portal" -FeatureId "8096285f-1463-42c7-82b7-f745e5bacf29" |
I have a "MissingFeature" in a database, but when I ran this script with -reportonly it did not find it. It does show up in CA, and when I try to export the site it gives the error that the "MissingFeature" is not installed on the farm.
Missing Feature: Id = [75a0fea7-040e-4abb-b94b-32f1e7572840]
I believe it's a fab40 reference.
Any idea how you can remove a reference this script doesn't see?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks, seems to work well!