SharePoint Online: Check if a Feature is Activated using PowerShell

Requirement: PowerShell to check if a feature is activated in SharePoint Online.

How to check if a specific Feature is Enabled in SharePoint?

If you are a SharePoint administrator, you may find yourself needing to know whether a specific feature is activated in your environment. This blog post will show you how to use PowerShell to check if a particular feature is activated on your SharePoint Online tenant. This can be helpful when troubleshooting issues or verifying that certain features are enabled.

To check the current status of a SharePoint feature, Say: Publishing Feature – follow these steps:

  1. Navigate to Site Settings >> Click on the “Site Collection Features” link under “Site collection administration (If it’s a site-level feature, use: the “Manage Site Features” link under the “Site Actions” group!)
  2. Check the button next to your feature. If the button shows just “Activate”, the feature is not activated. If the button shows “Deactivate” and the “Active” button is highlighted, then the feature is already activated.
    sharepoint online powershell check if feature is activated

SharePoint Online: PowerShell to Check if Feature is Activated

Before enabling or disabling a feature in SharePoint Online, we can check the current status of the feature in PowerShell with this script. Let’s take the example of “Publishing Feature” and check its status in both “Web” and “Site” scopes.

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
   
#Config Parameters
$SiteURL= "https://crescent.sharepoint.com"
$SiteFeatureGUID="f6924d36-2fa8-4f0b-b16d-06b7250180fa" #Publishing Feature - Site Scope
$WebFeatureGUID ="94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb" #Publishing Feature - Web Scope

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
 
Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Cred
   
    #Check the Site Collection Feature Status
    $SiteFeatureStatus =  $Ctx.Site.Features.GetById($SiteFeatureGuid)
    $SiteFeatureStatus.Retrieve("DefinitionId")
    $Ctx.Load($SiteFeatureStatus)
    $Ctx.ExecuteQuery()
 
    #Get the Site Collection Feature Status : Activated or not Activated
    if($SiteFeatureStatus.DefinitionId -ne $null)
    {
        Write-host -f Green "Site Collection Feature is Activated!"
    }
    else
    {
        Write-host -f Red "Site Collection Feature is Not Activated!"
    }

    #Get the Web Feature Status
    $WebFeatureStatus =  $Ctx.Web.Features.GetById($WebFeatureGuid)
    $WebFeatureStatus.Retrieve("DefinitionId")
    $Ctx.Load($WebFeatureStatus)
    $Ctx.ExecuteQuery()
 
    #Get the Site Collection Feature Status : Activated or not Activated
    if($WebFeatureStatus.DefinitionId -ne $null)
    {
        Write-host -f Green "Site Feature is Activated!"
    }
    else
    {
        Write-host -f Red "Site Feature is Not Activated!"
    }
}
Catch {
    write-host -f Red "Error Getting Feature Status!" $_.Exception.Message
}

So, All you need to do is: Set the feature GUID (How to Get Feature GUID in SharePoint?) and Site URL parameters in the script.

PnP PowerShell to Check If a Feature is Active in SharePoint Online Site

Use this PnP PowerShell cmdlet Get-PnPFeature to check if a feature is activated on the SharePoint Online site.

#Config Variable
$SiteURL = "https://Crescent.sharepoint.com/Sites/Marketing"
$FeatureId = "7c637b23-06c4-472d-9a9a-7c175762c5c4" #Limited Access user permission Lockdown mode feature

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#get the Feature
$Feature = Get-PnPFeature -Scope Site -Identity $featureId 

#Get the Feature status
If($Feature.DefinitionId -ne $null)
{
    Write-host -f Green "Site Collection Feature is Activated!"
}
Else
{
    Write-host -f Red "Site Collection Feature is Not Activated!"
}

You can change the scope to “web” to check if a web-scoped feature is active!

In summary, we have discussed how to check if a feature is activated in SharePoint Online using site settings and PowerShell. Following the steps outlined in this guide, you can quickly and easily verify that a specific feature is activated before performing an action in your SharePoint Online environment. Here are my related posts to activate or disable SharePoint Online features using PowerShell:

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

Leave a Reply

Your email address will not be published. Required fields are marked *