When you migrate from SharePoint 2007 to SharePoint 2010, You will found issues in content database upgrading process about feature being referenced and which are not available in the farm.
You can resolve this by using PowerShell script which will remove all the missing or orphan features.
$results = @()
foreach($site in Get-SPSite -limit all) {
#write-host "Site : " $site.URL
foreach ($feature in $site.features) {
$obj = New-Object PSObject
if ($feature.definition -eq $null) {
$obj | Add-Member NoteProperty "Site/Web Title"($site.Title)
$obj | Add-Member NoteProperty "Site/Web URL"($site.URL)
$obj | Add-Member NoteProperty "Feature ID"($feature.DefinitionId)
$results += $obj
$site.features.remove($feature.DefinitionId,$true)
}
}
$webs = $site | get-spweb -limit all
foreach ($web in $webs) {
foreach ($feature in $web.features) {
$obj = New-Object PSObject
if ($feature.definition -eq $null) {
$obj | Add-Member NoteProperty "Site/Web Title"($web.Title)
$obj | Add-Member NoteProperty "Site/Web URL"($web.URL)
$obj | Add-Member NoteProperty "Feature ID"($feature.DefinitionId)
$results += $obj
$web.Features.Remove($feature.DefinitionId, $true)
}
}
$web.dispose()
}
$site.dispose()
}
$results | Export-Csv "C:\MissingFeatures.csv" -notype
Above script will remove all the missing feature from all the site collections and its sub sites. And some code is there just to write a file report that how many features are removed from the site.
Sometime you will get error while some of the features saying:
Exception calling "Remove" with "2" argument(s): "Attempted to perform an unauthorized operation."
I got this error while executing the above script. I did some research and found something interesting saying that, If we add a feature on the publishing page with versioning enabled on and after we remove that feature from that, it will create new version of the page. Therefore the previous version of that page contains that feature. So to remove the feature we have to remove the version history where the feature was applied.
I am not sure but as we had some huge site collection we were not sure were we had used that feature.
But for we successfully removed many missing features using this script.
Thought this might be helpful to you all.
by Rahul Gokani via Everyone's Blog Posts - SharePoint Community
No comments:
Post a Comment