SharePoint Online: So sánh các tính năng giữa các trang web bằng PowerShell
Bạn đã bao giờ muốn so sánh các tính năng được kích hoạt giữa các bộ sưu tập hoặc trang SharePoint Site chưa? Chà, tập lệnh PowerShell tiện lợi này thực hiện chính xác điều đó!
PowerShell để so sánh các tính năng giữa các trang SharePoint Online hoặc các tuyển tập trang
Để so sánh các tính năng sẵn dùng trong hai site SharePoint Online, hãy làm theo các bước sau:
- Đăng nhập vào cả hai trang SharePoint Online bằng cùng một tài khoản.
- Điều hướng đến trang cài đặt trang cho từng trang.
- Trong trang cài đặt trang, nhấp vào “Tính năng trang web” trong “Hành động trang web”.
- Xem lại danh sách các tính năng được kích hoạt trong mỗi trang web và ghi lại những điểm khác biệt.
- Lặp lại quá trình cho cả hai trang web.
Hãy tự động hóa quy trình này bằng PowerShell để so sánh các tính năng trong hai trang SharePoint Online! Tập lệnh PowerShell này so sánh các tính năng được kích hoạt ở cả trang nguồn và trang đích và giúp bạn tìm ra sự khác biệt.
#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
Bạn có thể so sánh cả hai tính năng trong phạm vi “Web” và “Trang web” giữa hai trang web.
Tóm lại, so sánh các tính năng được kích hoạt trong hai trang SharePoint Online là một phương pháp hữu ích để hiểu sự khác biệt và tương đồng giữa hai trang. Quá trình này có thể được thực hiện thủ công bằng cách xem lại cài đặt trang, tuy nhiên, sử dụng Microsoft PowerShell để truy xuất danh sách các tính năng được kích hoạt và so sánh chúng sẽ là phương pháp hiệu quả. Thông tin này có thể được sử dụng để xác định những tính năng nào bị thiếu trên một trang web và quyết định có nên kích hoạt chúng hay không.
