Recently we did SharePoint 2013 to SharePoint 2013 migration from one domain to other domain. We did this migration with ‘Database Attach’ approach. During this migration, we have one of the task to complete is to disable particular feature from all webs within a web application. There were hundreds of sites within that web application and disabling the feature one by one would have taken days to complete that activity. So I created PowerShell script which does this within very less time.
Pre-requisite:
- Run this script on SharePoint Central Administration Server as Farm Administrator.
- Name of the feature which needs to be disabled.
- URL of target Web Application or Site Collection or Site (SPWeb).
How it works:
I created a generic script which takes three input parameters. First input parameter is $Scope, which takes values as Farm/WebApplication/Site/Web. Second parameter it takes is $Url which is required if you are running the script for Web Application/SiteCollection/Web. If you running this script on entire farm, you don’t need to specify value for this parameter as this is optional. The third parameter is $FeatureTitle which is mandatory.
- Param
- (
- [Parameter(Mandatory=$true, Position=0)]
- [ValidateSet("Farm","WebApplication","Site","Web")]
- [String]$Scope,
- [Parameter(Mandatory=$false, Position=1)]
- [String]$Url,
- [Parameter(Mandatory=$true, Position=2)]
- [ValidateNotNullOrEmpty()]
- [String]$FeatureTitle
- )
- if($Scope -ne $null -and $Url -ne $null)
- {
- if($Scope -eq "Farm")
- {
- #Finding all site collection within Farm
- $sites = Get-SPSite -Limit All -ErrorAction Stop
- }
- if($Scope -eq "WebApplication")
- {
- #Finding all site collection with particular Web Application.
- $sites = Get-SPSite -WebApplication $Url -Limit All -ErrorAction Stop
- }
- #Filtering site collections based on whether they are read-only, read-locked or Write-Locked. Such sites are excluded.
- $sites = $sites | Where-Object{$_.ReadOnly -ne $null -and $_.ReadLocked -ne $null -and $_.WriteLocked -ne $null}
- if($sites -ne $null)
- {
- foreach($site in $sites)
- {
- try
- {
- $webList += $site.AllWebs
- }
- catch
- {
- Write-Host -ForegroundColor Yellow "Site:"$site.Url
- Write-Host -ForegroundColor Red "Error:"$_.Exception.Message
- Start-Sleep -Seconds 5
- }
- $site.Dispose()
- }
- }
- if($Scope -eq "Site")
- {
- $webs = (Get-SPSite -Identity $url).AllWebs
- $webList += $webs
- }
- if($Scope -eq "Web")
- {
- $webList = Get-SPWeb -Identity $Url -ErrorAction Stop
- }
- if($webList -ne $null)
- {
- foreach($web in $webList)
- {
- Write-Host "Processing web:"$web.Url
- $targetFeature = $null
- $targetFeature = $web.Features | ?{$_.Definition.GetTitle(1033) -eq $FeatureTitle}
- #Get-SPFeature -Web $web -Limit All | select DisplayName, {$_.GetTitle(1033)}, Hidden, Status
- #$web.Features | ?{$_.Definition.Hidden -eq $false} | select {$_.Definition.GetTitle(1033)},{$_.Definition.DisplayName.ToString()},{$_.Definition.Status}, {$_.Definition.Hidden}
- if($targetFeature -ne $null)
- {
- Write-Host " Disabling feature "$targetFeature.Definition.GetTitle(1033)
- try
- {
- #Disable feature
- Disable-SPFeature -Identity $targetFeature -Url $web.Url -ErrorAction Stop -Confirm:$false
- Write-Host -ForegroundColor Green " Feature "$targetFeature.Definition.GetTitle(1033) " disabled successfully."
- }
- catch
- {
- Write-Host -ForegroundColor Red "Error disabling feature("$targetFeature.Definition.GetTitle(1033) "):"$_.Exception.Message
- }
- }
- else
- {
- Write-Host -ForegroundColor Yellow " Feature not found with specified name:"$FeatureTitle
- }
- $web.Dispose()
- }
- }
The complete script is attached to this article.

Santhakumar MunuswamyPosted Oct 18, 2015, 2:11 AM EDT
Good one
Sibeesh VenuTOP 100Posted Oct 6, 2015, 5:44 AM EDT
Nice Share
Harshad PansuriyaPosted Oct 6, 2015, 4:38 AM EDT
Nice One
Vinodh NarayananPosted Oct 6, 2015, 4:33 AM EDT
Nice one keep going
Priyaranjan K STOP 100Posted Oct 6, 2015, 1:42 AM EDT
Good One ..
Anit KumarPosted Oct 6, 2015, 12:34 AM EDT
Good one !!
Nilesh JadavPosted Oct 5, 2015, 11:36 PM EDT
Great Work sir
Ankit BansalPosted Oct 5, 2015, 11:14 PM EDT
nice..