Introduction

In this article, you will learn how retrieve, enable or disable the site level features (web scope) programmatically using CSOM with PowerShell on SharePoint 2013 / SharePoint online. This article applies to features present on web scope or sub sites level.

Steps Involved

The following prerequisites need to be executed before going for any operations using CSOM PowerShell on SharePoint sites.

  1. Add the references using the Add-Type command with necessary reference paths. The necessary references are Microsoft.SharePoint.Client.dll, Microsoft.SharePoint.Client.Runtime.dll.
    1. Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
    2. Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
  2. Initialize client context object with the site URL.
    1. $siteURL = ""
    2. $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL)
  3. If you are trying to access SharePoint Online site, then you need to setup the site credentials with credentials parameter and get it set to the client context.
    1. #Not required for on premise site - Start
    2. $userId = ""
    3. $pwd = Read-Host -Prompt "Enter password" -AsSecureString
    4. $creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userId, $pwd)
    5. $ctx.credentials = $creds
    6. #Not required for on premise site - End
  4. If you are trying to access the SharePoint on premise site, then the credentials parameter is not required to be set to the context. But you need to run the code on the respective SharePoint server or you need to pass the network credentials and set the context.
    1. #Credentials for on premise site - Start
    2. $pwd = Read-Host -Prompt "Enter password" -AsSecureString
    3. $creds = New-Object System.Net.NetworkCredential("", $pwd)
    4. $ctx.Credentials = $creds
    5. #Credentials for on premise site - End

Get Active Site Level Features (Web Scope)

Get/Check Site level Feature Properties/Status (Web Scope)

Here we will see how we can get the particular feature and check whether the site feature (web scope) is active or not.

Activate the site level feature (Web Scope)

In the above section, we have seen how we can check the status of the site level feature. Here we will see how we can activate the feature which is already installed on the site.

Deactivate the Site level feature (Web Scope)

In the above section, we have seen how we can activate the site level feature. Now we will see how we can deactivate the site level feature.

Summary

Thus you have learned how to retrieve, activate or de-activate the site level features (web scoped) using CSOM with PowerShell on SharePoint 2013 / SharePoint online sites.