Deactivate Feature on All Sites in SharePoint using PowerShell

Requirement: Disable a Feature on All SharePoint Sites.

After deploying Office web apps with edit licenses in SharePoint, we wanted to disable the open in client feature on all site collections in SharePoint. Deactivating a feature is straightforward from SharePoint web UI by getting into:

  • Site Settings >> Site Collection Features
  • Locate the target feature and click on “Deactivate” button next to it.
    sharepoint deactivate feature all sites using powershell

However, it’s cumbersome to repeat this activity for a larger number of site collections, isn’t it? So, use these PowerShell scripts to deactivate features from all sites in SharePoint!

PowerShell to Disable Feature on All Site Collections in SharePoint

In this blog post, we will show you how to disable a feature on all sites in SharePoint. This can be useful if you want to temporarily disable a feature on all of your sites, or if you need to disable a feature for troubleshooting purposes. We will be using the example of disabling the “Open Documents in Client Applications by Default” feature in SharePoint, but you can use this guide to disable any feature.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Feature to Deactivate
$FeatureID="8a4b8de2-6fd8-41e9-923c-c7c3c00f8295"

#Get all Site collections
$SitesColl= Get-SPWebApplication | Get-SPSite -Limit ALL
#Get the Feature
$Feature = Get-SPFeature | Where {$_.ID -eq $FeatureID}

#Check if Feature exists
if($Feature -ne $null)
{
    #Iterate through through each site collection and deactivate the feature
    Foreach($Site in $SitesColl)
    {
       #Check if the Feature is activated
       if (Get-SPFeature -Site $Site.Url | Where {$_.ID -eq $FeatureId})
       {
            #DeActivate the Feature
            Disable-SPFeature -identity $FeatureID -URL $Site.URL -Confirm:$false
            Write-Host "Feature has been Deactivated on "$Site.URL -f Green
       }
       else
       {
            Write-host "Feature was not activated on "$Site.URL -f Cyan
       }
    }
}
else    
{
    Write-Host "Feature doesn't exist:"$FeatureID -f Red
}

This script deactivates the given feature id from all site collections of the entire SharePoint environment.

Deactivate feature on all sites in SharePoint using PowerShell:

How about deactivating a feature on all sites (webs) in SharePoint? Use this PowerShell script to disable a feature for all sites:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Feature to Deactivate
$FeatureID="7201d6a4-a5d3-49a1-8c19-19c4bac6e668"

#Get all webs
$WebsColl= Get-SPWebApplication | Get-SPSite -Limit ALL | Get-SPWeb -Limit ALL

#Get the Feature
$Feature = Get-SPFeature | Where {$_.ID -eq $FeatureID}

#Check if Feature exists
if($Feature -ne $null)
{
    #Iterate through through each site collection and deactivate the feature
    Foreach($web in $WebsColl)
    {
       #Check if the Feature is activated
       if (Get-SPFeature -web $web.Url | Where {$_.ID -eq $FeatureId})
       {
            #DeActivate the Feature
            Disable-SPFeature -identity $FeatureID -URL $web.URL -Confirm:$false
            Write-Host "Feature has been Deactivated on "$web.URL -f Green
        }
        else
        {
            Write-host "Feature was not activated on "$web.URL -f Cyan
        }
    }
}
else    
{
    Write-Host "Feature doesn't exist:"$FeatureID -f Red
} 

This PowerShell script disables the given feature id from all subsites in SharePoint.

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

Leave a Reply

Your email address will not be published. Required fields are marked *