kwizcom banner advertisement

SharePoint Online: Check if Feature is Activated using PowerShell

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

How to Check if a specific Feature is Enabled in SharePoint?;
To check the current status of a SharePoint feature, Say: Publishing Feature - follow these steps:
  • Navigate to Site Settings >> Click on "Site Collection Features" link under "Site collection administration (If its a site level feature, use: "Manage Site Features" link under "Site Actions" group!)
  • Check the button next to your feature. If the button shows just "Activate" then the feature is not activated. If the button shows "Deactivate" and the "Active"highlighted then the feature is already activated.
    sharepoint online powershell check if feature is activated

SharePoint Online: PowerShell to Check if Feature is Activated
Prior to enabling or disabling a feature in SharePoint Online, we can check the current status of the feature in PowerShell with this script. Lets take an example of "Publishing Feature" and check its status in both in "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. Here is my related posts to activate or disable SharePoint Online features using PowerShell:
SharePoint Online: Check if Feature is Activated using PowerShell SharePoint Online: Check if Feature is Activated using PowerShell Reviewed by Salaudeen Rajack on April 29, 2017 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.