Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 7025

Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 2162

Deprecated: Hook imagify_allow_picture_tags_for_webp is deprecated since version 2.2! Use imagify_allow_picture_tags_for_nextgen instead. in /www/collab365_296/public/wp-includes/functions.php on line 5758
How to remove orphaned (missing) SharePoint Features with Powershell - Collab365
Deprecated: strstr(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1145

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1152

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1155

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1162

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1165

Deprecated: strstr(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1145

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1152

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1155

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1162

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1165

Warning: Undefined array key "url" in /www/collab365_296/public/wp-content/plugins/thrive-visual-editor/thrive-dashboard/inc/smart-site/classes/class-tvd-smart-shortcodes.php on line 85

2015-10-09

When you upgrade to a newer version of SharePoint, you will no doubt find issues with SharePoint Features that aren’t in the newer Farm. This results in one or more orphaned features. You can either deploy the Features to the new Farm, or you can remove them with this script:

$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

Running the Script above will remove all of the missing Features from all of the Site Collections as well as each Sub Site. There’s also some code to log the progress.

Note: Sometime’s you may get the following error:

Exception calling "Remove" with "2" argument(s): "Attempted to perform an unauthorized operation."

If you do receive this error, then it could be down to publishing pages (with versioning enable). 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.

 

(Visited 949 times, 1 visits today)

About the author 

Rahul Gokani

Summit Bundle

Get 200+ hours of Microsoft 365 Training for 27$!

Master Office 365, Power Platform & SharePoint & Teams With 200+ Hours Of Training Videos and 108 Ebooks in the Collab365 Academy. This offer is insane and is only available for a limited period.