Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
SharePoint PowerShell : Remove Missing Features From Content Database
WhatsApp
Ketak Bhalsing
Apr 22
2016
11
k
0
0
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
}
}
$contentDatabaseName = Read-Host
"Enter the Content Datbase name:"
$featureId = Read-Host
"Enter the feature Id :"
Remove-SPFeatureFromContentDB -ContentDB $contentDatabaseName -FeatureId $featureId –ReportOnly
SharePoint
PowerShell
Up Next
SharePoint PowerShell : Remove Missing Features From Content Database