Skip to content

Commit c27f679

Browse files
000-551: comparetenants
1 parent 8e13d94 commit c27f679

File tree

1 file changed

+239
-12
lines changed

1 file changed

+239
-12
lines changed

articles/en/spo/comparetenants.md

Lines changed: 239 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,246 @@ If a new policy or feature is enabled in one tenant, comparing with a baseline t
4444

4545

4646

47-
# How - SPO Management Shell
48-
49-
You need to connect to both tenants using the Connect-SPOService cmdlet and get the properties using the Get-SPOTenant cmdlet.
50-
51-
52-
53-
# How - PnP Powershell
54-
55-
# How - CSOM
56-
57-
58-
47+
# Compare SharePoint tenant settings using SPO Management Shell
48+
49+
You need to connect to both tenants using the `Connect-SPOService` cmdlet and get the properties using the `Get-SPOTenant` cmdlet. Then compare all the properties. Two files will be genrated:
50+
one - full list of all the compared SharePoint properties, called FullTenantComparison.csv
51+
two - only the differences between the Microsoft 365 tenants, called TenantDifferences
52+
53+
```powershell
54+
# Define a function to connect to a tenant and get properties
55+
function Get-TenantProperties {
56+
param (
57+
[string]$AdminUrl
58+
)
59+
60+
Write-Host "Connecting to $AdminUrl..." -ForegroundColor Cyan
61+
Connect-SPOService -Url $AdminUrl
62+
$tenantProperties = Get-SPOTenant | Select-Object *
63+
Disconnect-SPOService
64+
return $tenantProperties
65+
}
66+
67+
# Define a function to compare two objects
68+
function Compare-TenantProperties {
69+
param (
70+
[PSCustomObject]$Tenant1,
71+
[PSCustomObject]$Tenant2
72+
)
73+
74+
$comparison = @()
75+
foreach ($property in $Tenant1.PSObject.Properties) {
76+
$propertyName = $property.Name
77+
$value1 = $Tenant1.$propertyName
78+
$value2 = $Tenant2.$propertyName
79+
80+
$comparison += [PSCustomObject]@{
81+
PropertyName = $propertyName
82+
Tenant1Value = $value1
83+
Tenant2Value = $value2
84+
IsDifferent = $value1 -ne $value2
85+
}
86+
}
87+
return $comparison
88+
}
89+
90+
# Enter the admin URLs for the two tenants
91+
$Tenant1AdminUrl = "https://tenant1-admin.sharepoint.com"
92+
$Tenant2AdminUrl = "https://tenant2-admin.sharepoint.com"
93+
94+
# Get properties from both tenants
95+
$Tenant1Properties = Get-TenantProperties -AdminUrl $Tenant1AdminUrl
96+
$Tenant2Properties = Get-TenantProperties -AdminUrl $Tenant2AdminUrl
97+
98+
# Compare the properties
99+
$ComparisonResults = Compare-TenantProperties -Tenant1 $Tenant1Properties -Tenant2 $Tenant2Properties
100+
101+
# Filter only the differences
102+
$Differences = $ComparisonResults | Where-Object { $_.IsDifferent -eq $true }
103+
104+
# Output to console
105+
Write-Host "Comparison complete." -ForegroundColor Green
106+
107+
# Export all settings compared
108+
$ComparisonResults | Export-Csv -Path "TenantComparison_Full.csv" -NoTypeInformation -Encoding UTF8
109+
Write-Host "Full comparison exported to TenantComparison_Full.csv" -ForegroundColor Cyan
110+
111+
# Export only differences
112+
$Differences | Export-Csv -Path "TenantComparison_Differences.csv" -NoTypeInformation -Encoding UTF8
113+
Write-Host "Differences exported to TenantComparison_Differences.csv" -ForegroundColor Cyan
114+
115+
```
116+
117+
# Compare SharePoint tenant settings using PnP Powershell
118+
119+
You need to connect to both tenants using the `Connect-PnPOnline` cmdlet and get the properties using the `Get-PnPTenant` cmdlet. Then compare all the properties. Two files will be genrated:
120+
one - full list of all the compared SharePoint properties, called FullTenantComparison.csv
121+
two - only the differences between the Microsoft 365 tenants, called TenantDifferences
122+
123+
```powershell
124+
125+
# Connect to the first tenant
126+
$Tenant1Url = "https://tenant1-admin.sharepoint.com"
127+
$Tenant2Url = "https://tenant2-admin.sharepoint.com"
128+
129+
Write-Host "Connecting to Tenant 1: $Tenant1Url" -ForegroundColor Cyan
130+
Connect-PnPOnline -Url $Tenant1Url -Interactive
131+
$Tenant1Properties = Get-PnPTenant | Select-Object -Property *
132+
133+
# Connect to the second tenant
134+
Write-Host "Connecting to Tenant 2: $Tenant2Url" -ForegroundColor Cyan
135+
Connect-PnPOnline -Url $Tenant2Url -Interactive
136+
$Tenant2Properties = Get-PnPTenant | Select-Object -Property *
137+
138+
# Compare the tenant properties
139+
Write-Host "Comparing properties..." -ForegroundColor Yellow
140+
$Comparison = @()
141+
$AllProperties = $Tenant1Properties.PSObject.Properties.Name
142+
143+
foreach ($Property in $AllProperties) {
144+
$Value1 = $Tenant1Properties.$Property
145+
$Value2 = $Tenant2Properties.$Property
146+
147+
if ($Value1 -ne $Value2) {
148+
$Comparison += [PSCustomObject]@{
149+
PropertyName = $Property
150+
Tenant1Value = $Value1
151+
Tenant2Value = $Value2
152+
}
153+
}
154+
}
155+
156+
# Output the differences
157+
if ($Comparison.Count -gt 0) {
158+
Write-Host "Differences found:" -ForegroundColor Green
159+
$Comparison | Format-Table -AutoSize
160+
161+
# Export differences to CSV
162+
$Comparison | Export-Csv -Path "TenantDifferences.csv" -NoTypeInformation
163+
Write-Host "Differences exported to TenantDifferences.csv" -ForegroundColor Green
164+
} else {
165+
Write-Host "No differences found between the two tenants." -ForegroundColor Green
166+
}
167+
168+
# Output all properties for full comparison
169+
$FullComparison = @()
170+
foreach ($Property in $AllProperties) {
171+
$FullComparison += [PSCustomObject]@{
172+
PropertyName = $Property
173+
Tenant1Value = $Tenant1Properties.$Property
174+
Tenant2Value = $Tenant2Properties.$Property
175+
}
176+
}
177+
178+
# Export full comparison to CSV
179+
$FullComparison | Export-Csv -Path "FullTenantComparison.csv" -NoTypeInformation
180+
Write-Host "Full comparison exported to FullTenantComparison.csv" -ForegroundColor Green
181+
182+
183+
```
184+
185+
# Compare SharePoint tenant settings using CSOM
186+
187+
188+
First connect to both tenants and export the SharePoint tenant properties by loading `Microsoft.Online.SharePoint.TenantAdministration.Tenant` object for each Microsoft 365 tenant. Then compare all the properties. Two files will be genrated:
189+
one - full list of all the compared SharePoint properties, called FullTenantComparison.csv
190+
two - only the differences between the Microsoft 365 tenants, called TenantDifferences
191+
192+
193+
```powershell
194+
195+
# Load required assemblies
196+
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
197+
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
198+
199+
# Function to get tenant properties
200+
function Get-TenantProperties {
201+
param (
202+
[string]$AdminUrl,
203+
[string]$Username,
204+
[string]$Password
205+
)
206+
207+
$securePassword = ConvertTo-SecureString -String $Password -AsPlainText -Force
208+
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $securePassword)
209+
210+
$context = New-Object Microsoft.SharePoint.Client.ClientContext($AdminUrl)
211+
$context.Credentials = $credentials
212+
213+
# Load tenant properties
214+
$tenant = New-Object Microsoft.Online.SharePoint.TenantAdministration.Tenant($context)
215+
$context.Load($tenant)
216+
$context.ExecuteQuery()
217+
218+
# Extract and return tenant properties
219+
return $tenant | Get-Member -MemberType Property | ForEach-Object {
220+
[PSCustomObject]@{
221+
PropertyName = $_.Name
222+
PropertyValue = $tenant.($_.Name)
223+
}
224+
}
225+
}
226+
227+
# Connect to the first tenant
228+
$Tenant1AdminUrl = "https://tenant1-admin.sharepoint.com"
229+
$Tenant1Username = "admin1@tenant1.onmicrosoft.com"
230+
$Tenant1Password = "YourPassword1"
231+
232+
Write-Host "Retrieving properties from Tenant 1: $Tenant1AdminUrl" -ForegroundColor Cyan
233+
$Tenant1Properties = Get-TenantProperties -AdminUrl $Tenant1AdminUrl -Username $Tenant1Username -Password $Tenant1Password
234+
235+
# Connect to the second tenant
236+
$Tenant2AdminUrl = "https://tenant2-admin.sharepoint.com"
237+
$Tenant2Username = "admin2@tenant2.onmicrosoft.com"
238+
$Tenant2Password = "YourPassword2"
239+
240+
Write-Host "Retrieving properties from Tenant 2: $Tenant2AdminUrl" -ForegroundColor Cyan
241+
$Tenant2Properties = Get-TenantProperties -AdminUrl $Tenant2AdminUrl -Username $Tenant2Username -Password $Tenant2Password
242+
243+
# Compare tenant properties
244+
Write-Host "Comparing properties..." -ForegroundColor Yellow
245+
$Comparison = @()
246+
247+
foreach ($Property in $Tenant1Properties) {
248+
$Tenant2Value = ($Tenant2Properties | Where-Object { $_.PropertyName -eq $Property.PropertyName }).PropertyValue
249+
250+
if ($Property.PropertyValue -ne $Tenant2Value) {
251+
$Comparison += [PSCustomObject]@{
252+
PropertyName = $Property.PropertyName
253+
Tenant1Value = $Property.PropertyValue
254+
Tenant2Value = $Tenant2Value
255+
}
256+
}
257+
}
258+
259+
# Output the differences
260+
if ($Comparison.Count -gt 0) {
261+
Write-Host "Differences found:" -ForegroundColor Green
262+
$Comparison | Format-Table -AutoSize
263+
264+
# Export differences to CSV
265+
$Comparison | Export-Csv -Path "TenantDifferences.csv" -NoTypeInformation
266+
Write-Host "Differences exported to TenantDifferences.csv" -ForegroundColor Green
267+
} else {
268+
Write-Host "No differences found between the two tenants." -ForegroundColor Green
269+
}
270+
271+
# Output all properties for full comparison
272+
$FullComparison = $Tenant1Properties | ForEach-Object {
273+
$Tenant2Value = ($Tenant2Properties | Where-Object { $_.PropertyName -eq $_.PropertyName }).PropertyValue
274+
275+
[PSCustomObject]@{
276+
PropertyName = $_.PropertyName
277+
Tenant1Value = $_.PropertyValue
278+
Tenant2Value = $Tenant2Value
279+
}
280+
}
59281
282+
# Export full comparison to CSV
283+
$FullComparison | Export-Csv -Path "FullTenantComparison.csv" -NoTypeInformation
284+
Write-Host "Full comparison exported to FullTenantComparison.csv" -ForegroundColor Green
285+
286+
```
60287

61288

62289
# See Also

0 commit comments

Comments
 (0)