Friday, May 8, 2015

I want to automatically activate a feature automatically when I deploy a new wsp solution and and activate wsp. Is this possible.

hi

below is script 

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
 $webs =  get-spsite -webapplication "http://ift.tt/1H3soGd;
 $feature = "YourFeatureName" #this might not be what you expect it to be, best to do get-spfeature | Select displayname
 
  Foreach ($oneweb in $webs)
  {
    write-host $oneweb
    $siteFeature = get-spfeature -site $oneweb | Where {$_.displayname -eq $feature}
    if ($siteFeature -eq $null)
    {
      Write-Host "Activating Site level Features at $oneweb" -foregroundcolor Yellow
      Enable-SPFeature -Identity $Feature -URL $oneweb.URL -Confirm:$False
    }
    else
    {
      Write-Host "Feature $feature is already activated on $oneweb" -foregroundcolor green
    }
  }

You can add multiple feature by adding $feature1,$feature2 like that and you can customized to particular site by 

$webs =  get-spsite  "url of the site collection"

Rajendra Singh
Walking on water and developing software from a specification are easy if both are frozen
If a post answers your question, please click Mark As Answer on that post and Vote as Helpful

No comments:

Post a Comment