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 - Enable/Disable Ribbon Button with EcmaScript

Sharepoint 2010 - Customizing Quick Launch with pages

SharePoint - Add button Apply to List Item Edit Form for Saving Item without closing form