Saturday, February 13, 2016

Deactivate Feature on All Sites in SharePoint using PowerShell

Requirement: 
After deploying Office web apps with edit licenses in SharePoint, we wanted to disable open in client feature on all site collections in SharePoint. Deactivating a feature is straight forward 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
However, its cumbersome to repeat this activity for 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
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.



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...