Thursday, June 7, 2012

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:

$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

No comments:

Post a Comment