Activate a site feature in  SharePoint Online using PnP PowerShell

Activate a site feature in SharePoint Online using PnP PowerShell

In my previous blog about Introduction to SharePoint Spaces, I explained different methods to enable SharePoint spaces in a SharePoint online site. One of the method was to activate a Spaces feature using PnP PowerShell.

So, I thought of writing a separate blog on how to activate a site feature in SharePoint Online using PnP PowerShell.

In SharePoint Online, we can easily activate a feature using Enable-PnPFeature cmdlet. To activate a feature using PnP PowerShell you will need the GUID of feature. Check how you can quickly get the GUID of a site feature.

In this blog, we will activate a site level feature named Spaces whose GUID is 2ac9c540-6db4-4155-892c-3273957f1926.

$siteUrl = "https://tenant.sharepoint.com/Sites/siteName"
$featureScope = "Web"	#Scope of feature 
$featureId = "2ac9c540-6db4-4155-892c-3273957f1926"	#SharePoint Spaces Feature
 
#Connect to SharePoint site
Connect-PnPOnline -Url $siteURL -Interactive
 
#Get Feature from SharePoint site
$spacesFeature = Get-PnPFeature -Scope $featureScope -Identity $featureId
 
#Check if feature is already activated or not
if($spacesFeature.DefinitionId -eq $null) {  
    Write-host "Activating Feature ($featureId)..." 
	
    #Activate the Feature
    Enable-PnPFeature -Scope Site -Identity $FeatureId -Force
 
    Write-host -f Green "Feature ($featureId) has been activated Successfully!"
}
else {
    Write-host "Feature ($featureId) is already active on this site!"
}

Output:

SharePoint online Site Features Settings in Manage site features
Activated Spaces feature

Similarly, you can also activate the site collection level features by changing -Scope to “Site”.

I hope you liked this blog. Give your valuable feedback & suggestions in the comments section below and share this blog with others.