SharePoint Online: Get All Features using PowerShell
Requirement: SharePoint Online PowerShell to List Features.
How to Get Site features in SharePoint Online?
Microsoft SharePoint Online is a great platform that provides many features and functionality. In some instances, you may need to see a list of all the available features on your sites. In this blog post, I will show you how to use PowerShell to access all of the features available in SharePoint Online.
To access features in SharePoint Online, Go to Site Settings >> Click on “Site Features” to access web-scoped features. Similarly, click on “Site Collection Features” to access a list of site collection features.
SharePoint Online: Get Site Collection Features PowerShell
Let’s list SharePoint Online site features using PowerShell. This PowerShell script gets all features present in a given URL’s site and web scopes.
#Import SharePoint Online Management Shell
Import-Module Microsoft.Online.Sharepoint.PowerShell -DisableNameChecking
#Variables
$SiteURL="https://Crescent.sharepoint.com"
#Setup Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
#Get Site Collection Features
$SiteCollFeatures = $Ctx.Site.Features
$Ctx.Load($SiteCollFeatures)
$Ctx.ExecuteQuery()
#Loop through each feature and get feature data
Write-host "Site Collection Features:"
ForEach($Feature in $SiteCollFeatures)
{
$Feature.Retrieve("DisplayName")
$Ctx.Load($Feature)
$Ctx.ExecuteQuery()
$Feature | Select DisplayName, DefinitionId
}
SharePoint Online: PowerShell to Get Features
Here is the PowerShell to get SharePoint Online features at web scope.
#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"
#Variables
$SiteURL="https://Crescent.sharepoint.com"
#Setup Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
#Get Web Level Features
Write-host "`nWeb Scoped Features:"
#Get web Features
$WebFeatures = $Ctx.Web.Features
$Ctx.Load($WebFeatures)
$Ctx.ExecuteQuery()
#Loop through each feature and get feature data
ForEach($Feature in $WebFeatures)
{
$Feature.Retrieve("DisplayName")
$Ctx.Load($Feature)
$Ctx.ExecuteQuery()
$Feature | Select DisplayName, DefinitionId
}
PnP PowerShell to Get Site Collection Features in SharePoint Online:
To get features from the SharePoint Online site, use the Get-PnPFeature cmdlet. If you want to filter the list of features by a specific scope, you can use the “Scope” parameter. For example, to get a list of all features that are site-scoped, run the following script:
#Config Variable
$SiteURL = "https://Crescent.sharepoint.com/Sites/Marketing"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Get Site Collection Features
Get-PnPFeature -Scope Site | Select DisplayName, DefinitionID
The above script gets the feature name and ID of all activated features at the site level. Similarly, you can retrieve web-scoped features as:
#Config Variable
$SiteURL = "https://Crescent.sharepoint.com/Sites/Marketing"
$FeatureScope = "Web" #Scope of the Feature
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
#Get Web Features
Get-PnPFeature -Scope $FeatureScope | Select DisplayName, DefinitionID
This will return all activated web-scoped features.
Related Articles:
- To activate a SharePoint Online feature using PowerShell: SharePoint Online Activate Publishing Feature using PowerShell
- To deactivate SharePoint Online features PowerShell: SharePoint Online PowerShell to Disable Feature