Introduction
In this article, you will learn how we can retrieve, activate or deactivate Web scoped features on SharePoint sites or sub sites, using PnP PowerShell. The Client Side Object Model is used internally for these operations.
Prerequisite
You need to have PowerShell 3.0 available on a Windows machine. You need to install or import PnP PowerShell packages. You can download the installers or view more documentation on the official site. The installers are available here. Online version installer is preferred for On Premise or Office 365 operations. You can also install all the three installers for testing (SharePoint 2013, 2016, online).
The following operations will be compatible with SharePoint 2013 On Premise and Office 365 versions.
Connect To Site
Connect to the site, using the snippet given below. PnP PowerShell code, given below, helps in getting the current context of the site, using the Client Side Object Model (CSOM).
- #Get Current Context Site (Root or subsite)
- $siteurl = "https://abc.sharepoint.com/subsite"
- Connect-SPOnline -Url $siteurl
- $ctx = Get-SPOContext
Since we are working with the features with Web Scope, the site URL can be the site collection or sub sites available. Once connected, you can carry out any of the operations mentioned below, based on the requirement.
Retrieve Web Scope Features
The Web scoped features active on the site or sub sites are retrieved in the operation given below. Get-SPOFeature command is used to get all the features from the site. Since we are retrieving the Web scoped features, the scope parameter is not required in this operation.
Each and every feature's information is retrieved using for each loop. The display name and definition Id are retrieved from the features. The code snippet given below helps in retrieving all the Web scoped features from the site or sub site specified in the context.
- function RetrieveFeatures(){
- # Get Web Scoped features
- $features = Get-SPOFeature -Scope Web
- Write-Host "Total active features count " $features.Count
- foreach($feature in $features){
- Write-Host "Feature Name : " $feature.DisplayName
- Write-Host "Feature ID : " $feature.DefinitionId
- }
- }
- RetrieveFeatures #Get all web scoped features from site
The feature can be retrieved using the identity. The identity can be the feature name or Id. The scope parameter is optional, though Web is passed as a scope. The following code snippet retrieves the feature, using the feature Id.



Saineshwar BageriPosted Jul 4, 2016, 1:10 PM
Nice one
Vignesh ManiPosted Jul 4, 2016, 11:09 AM
Nice
kalu singh raoPosted Jul 4, 2016, 1:37 AM
Nice...
RajaPosted Jul 4, 2016, 12:35 AM
Nice Share...