SharePoint Online: Compare Features Between Sites using PowerShell
Have you ever wanted to compare features activated between SharePoint Site collections or sites? Well, this nifty PowerShell script does that exactly!
PowerShell to Compare Features Between SharePoint Online Sites or Site Collections
To compare features available in two SharePoint Online sites, follow these steps:
- Log in to both SharePoint Online sites using the same account.
- Navigate to the site settings page for each site.
- In the site settings page, click on “Site features” under “Site Actions”.
- Review the list of features that are activated in each site and take note of the differences.
- Repeat the process for both sites.
Let’s automate this process using PowerShell to compare the features in two SharePoint Online sites! This PowerShell script compares the features activated in both source and target sites and gets you the difference.
#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"
Function Compare-SPOFeatures
{
[cmdletbinding()]
Param(
[Parameter(Mandatory=$True)][URI]$SourceSiteURL,
[Parameter(Mandatory=$True)][URI]$TargetSiteURL,
[Parameter(Mandatory=$True)][ValidateSet('Site','Web')][String]$Scope
)
#Get Credentials to connect
$Cred = Get-Credential
#Get Source and Target Site Contexts
$SourceCtx = New-Object Microsoft.SharePoint.Client.ClientContext($SourceSiteURL.AbsoluteUri)
$SourceCtx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
$TargetCtx = New-Object Microsoft.SharePoint.Client.ClientContext($TargetSiteURL.AbsoluteUri)
$TargetCtx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
#Get Features based on Given Scope
Switch($Scope)
{
Site
{
Write-Host -f Yellow "Comparing Features Between Site Collections..."
$SourceFeatures = $SourceCtx.Site.Features
$TargetFeatures = $TargetCtx.Site.Features
$SourceCtx.Load($SourceFeatures)
$TargetCtx.Load($TargetFeatures)
$SourceCtx.ExecuteQuery()
$TargetCtx.ExecuteQuery()
}
Web
{
Write-Host -f Yellow "Comparing Features Between Sites..."
$SourceFeatures = $SourceCtx.Web.Features
$TargetFeatures = $TargetCtx.Web.Features
$SourceCtx.Load($SourceFeatures)
$TargetCtx.Load($TargetFeatures)
$SourceCtx.ExecuteQuery()
$TargetCtx.ExecuteQuery()
}
}
$MismatchedFeatures = New-Object System.Collections.Arraylist
ForEach($Feature in $SourceFeatures)
{
$Feature.Retrieve("DisplayName")
$SourceCtx.Load($Feature)
$SourceCtx.ExecuteQuery()
If(!($TargetFeatures.DefinitionId -Match $Feature.DefinitionId))
{
$FeatureEntry = New-Object System.Object
$FeatureEntry | Add-Member -MemberType NoteProperty -Name "Feature Name" -Value $Feature.DisplayName
$FeatureEntry | Add-Member -MemberType NoteProperty -Name "Feature ID" -Value $Feature.DefinitionID
$FeatureEntry | Add-Member -MemberType NoteProperty -Name "Activated In" -Value "Source Only"
$MismatchedFeatures.Add($FeatureEntry) | Out-Null
}
}
ForEach($Feature in $TargetFeatures)
{
$Feature.Retrieve("DisplayName")
$TargetCtx.Load($Feature)
$TargetCtx.ExecuteQuery()
If(!($SourceFeatures.DefinitionId -Match $Feature.DefinitionId))
{
$FeatureEntry = New-Object System.Object
$FeatureEntry | Add-Member -MemberType NoteProperty -Name "Feature Name" -Value $Feature.DisplayName
$FeatureEntry | Add-Member -MemberType NoteProperty -Name "Feature ID" -Value $Feature.DefinitionID
$FeatureEntry | Add-Member -MemberType NoteProperty -Name "Activated In" -Value "Target Only"
$MismatchedFeatures.Add($FeatureEntry) | Out-Null
}
}
Return $MismatchedFeatures
}
#Call the Function to compare features between site collections
Compare-SPOFeatures -SourceSiteURL "https://crescent.sharepoint.com/sites/marketing" -TargetSiteURL "https://crescent.sharepoint.com/sites/creditpipeline" -Scope Site
You can compare both “Web” scoped and “Site” scoped features between two sites.
In conclusion, comparing features activated in two SharePoint Online sites is a useful method to understand the differences and similarities between the two sites. This process can be performed manually by reviewing the site settings, however using Microsoft PowerShell to retrieve the list of activated features and comparing them would be the efficient approach. This information can be used to identify which features are missing from one site and decide whether to activate them or not.