Sharepoint 2010: Deactivate and Activate Feature with Power Shell

Sometimes, you can have trouble with feature upgrade in your site.
Especially if you upgrade event receiver, adding new trigger.
If you have many sub site using this feature, you can use Power Shell to deactivate and activate feature.

This mine:


[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$rootUrl = "http://[SERVERNAME]"
$site = Get-SPSite $rootUrl
foreach($web in $site.AllWebs)
{
  $url = $web.Url
  if($url -ne $rootUrl){
   foreach($feature in Get-SPFeature -Web $url)
   {
    $featureName = $feature.DisplayName
    if($featureName -eq "FEATURE NAME")
    {
      "Disable and Enable feature $featureName in $web"
      Disable-SPFeature -Identity FEATURENAME -Url $url -Confirm:$false
      Enable-SPFeature -Identity  FEATURENAME -Url $url
      break;
    }
   }
  }
}

Comments

Popular posts from this blog

Sharepoint 2010 - Filter List/Library Web Part with XSLT and Content Editor WP

Sharepoint 2010 - Multilanguage Site - Show column in current language

Sharepoint 2010 - Enable/Disable Ribbon Button with EcmaScript