Monday 9 June 2014

PowerShell Script to check for Feature Activation/ PowerShell Script to Activate Feature at Web Scope


Below PowerShell script will check for WebFeature with Feature id *********, is active or not,  in all the SiteCollections in a WebApplication.

If the feature is not active it will go and enable it. 

Get-SPFeature will get list of all Features which as different scopes Farm, WebApplication, Site, Web

As we are interested in Activating feature with Web Scope at all webs hence we are using scope as -Web.



cls
asnp "*sh*"
try
{
$web=Get-SPWebApplication   "http://SP2013LocalDev/" | Get-spsite -Limit All | get-spweb -Limit All | % {

$bool=Get-SPFeature -Web $_ | where {$_.Id -eq "54944497-1d5b-443d-aba9-d20991ed18bb"}
  
                    if(!$bool)
                    {
                    Enable-SPFeature -Identity "54944497-1d5b-443d-aba9-d20991ed18bb" -Url $_.Url
                    Write-Host  "Feature Activated"
                    }
          else
          {
          Write-Host "Feature is Active at" $_.Url
          }
     
       }
      
}
catch{
             $ErrorMessage = $_.Exception.Message
             Write-Host $web.Title  $ErrorMessage
       }


No comments:

Post a Comment