I am developing a script to refresh my custom features. Earlier i was just looping through the features and calling Disable-SPFeature and Enable-SPFeature on each items.

The issue is when the feature is not activated. I would like to check if feature is already activated on the scope and taking appropriate action based on the feature status.

any help, pointers


4 Answers 4


To check the state of a feature use

(Get-SPFeature -Identity <FEATURE> -ErrorAction SilentlyContinue -Farm/-WebApplication/ -Site/-Web ) -ne $null

The extra -Scope parameter will check if the feature is active at that scope.

See MSDN Get-SPFeature

If you want to activate the feature then a try/catch trap block can be used

    Enable-SPFeature -Identity <FEATURE> -Url <SCOPE> -ErrorAction Stop
catch [System.Management.Automation.ActionPreferenceStopException]
    if( !($_.Exception -is [System.Data.DuplicateNameException]) )
        #Its not a "feature is already activated at scope" exception
        #Handle the "feature is already activated at scope" exception

But as you can see it's not pretty.

  • +1 Not pretty like many things in this with SharePoint and PowerShell but you can get them to work, this is the method we use for deploying WSP's with PowerShell and making sure things are active.
    – MichaelF
    May 19, 2011 at 20:29
  • We chose the catch approach as we weren't happy with -ErrorAction SilentlyContinue it would silently swallow feature activation exceptions and other unexpected errors.
    – Steve P
    May 20, 2011 at 5:54
  • Hey Thanks for your answer:- "(Get-SPFeature -Identity <FEATURE> -ErrorAction SilentlyContinue -Farm/-WebApplication/ -Site/-Web <URL>) -ne $null" this seems to be doing the trick. May 21, 2011 at 11:47

You can use SharePoint object model from PowerShell to achieve this:

PS C:\Users\omlin> $featureGuid = "PUT-GUID-HERE"
PS C:\Users\omlin> $web = Get-SPWeb http://localhost
PS C:\Users\omlin> $feature = $web.Features[$featureGuid]
PS C:\Users\omlin> if ($feature -eq $null) { "does not activated" } else { "activated" }
does not activated
PS C:\Users\omlin>
function Check-SPFeatureActivated
    param([string]$Id=$(throw "-Id parameter is required!"),
            [Microsoft.SharePoint.SPFeatureScope]$Scope=$(throw "-Scope parameter is required!"),
    if($Scope -ne "Farm" -and [string]::IsNullOrEmpty($Url))
        throw "-Url parameter is required for scopes WebApplication,Site and Web"

        "Farm" { $feature=Get-SPFeature $Id -Farm }
        "WebApplication" { $feature=Get-SPFeature $Id -WebApplication $Url }
        "Site" { $feature=Get-SPFeature $Id -Site $Url }
        "Web" { $feature=Get-SPFeature $Id -Web $Url }
    #return if feature found or not (activated at scope) in the pipeline
    $feature -ne $null

Check-SPFeatureActivated -Id 00bfea71-1e1d-4562-b56a-f05371bb0115 -Scope "Web" -Url "http://mysharepointsite/"
  • this will throw exceptions if the feature is not active. I think that if the scenario assume that the GUID is always valid (e.g. it was retrieved from another cmdlet against the farm) you can safely add -ErrorAction SilentlyContinue to the Get-SPFeature cmdlet, you will avoid exceptions and it assumes that4 when it errors out the feature is not active Nov 5, 2013 at 16:03


Here is the simple script to check whether feature is activated or not in all the sitecollections in a Webapplication, if the feature is not active go and enable the feature. Here we are using feature id to check for feature.


Add-PSSnapin "Microsoft.SharePoint.Powershell" 

$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"}

                Enable-SPFeature -Identity "54944497-1d5b-443d-aba9-d20991ed18bb" -Url $_.Url
                Write-Host  "Feature Activated"
      Write-Host "Feature is Active at" $_.Url


         $ErrorMessage = $_.Exception.Message
         Write-Host $web.Title  $ErrorMessage

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.