feat(compare): add offline tenant comparison and launcher menu entry

Scripts/Compare-Tenants.py compares two export folders across all
common categories (settings catalog, device config, compliance,
autopilot, ESP, roles, apps, ...) by flattening objects and ignoring
ids, timestamps, scope tags, OData metadata and names. Policies are
matched by name after stripping per-tenant prefixes (regex), then by
fuzzy name similarity, then by content similarity. Optional assignment
comparison. Writes Markdown and CSV reports.

Start-IntuneToolkit.ps1: new menu item 22 prompts for both exports and
runs the script.
This commit is contained in:
2026-11-24 11:56:43 +01:00
parent 7e1349f1c9
commit 5d8e387288
4 changed files with 379 additions and 0 deletions
+43
View File
@@ -328,6 +328,7 @@ $menuItems = @(
# Reporting
"16. Generate reports"
"20. Export Entra role membership"
"22. Compare two tenant exports (offline)"
# Tenant & auth admin
"12. Initialize auth (one-time setup)"
"13. Refresh tenant names"
@@ -490,6 +491,48 @@ while($true)
continue
}
if($choiceNumber -eq 22)
{
# Offline comparison of two export folders; no tenant connection needed
$python = Get-Command python3 -ErrorAction SilentlyContinue
if(-not $python) { $python = Get-Command python -ErrorAction SilentlyContinue }
if(-not $python) { Write-Host "Python 3 is required." -ForegroundColor Red; continue }
$sides = @()
foreach($side in "A","B")
{
$root = Read-Host "Export folder of tenant $side"
if([string]::IsNullOrWhiteSpace($root)) { Write-Host "Required." -ForegroundColor Red; $sides = $null; break }
$root = [IO.Path]::GetFullPath(($root.Trim().Trim('"',"'") -replace '^~', $HOME))
if(-not (Test-Path -LiteralPath $root -PathType Container)) { Write-Host "Folder not found: $root" -ForegroundColor Red; $sides = $null; break }
$defaultLabel = Split-Path $root -Leaf
$label = Read-Host "Label for tenant $side (default: $defaultLabel)"
if([string]::IsNullOrWhiteSpace($label)) { $label = $defaultLabel }
$strip = Read-Host "Name prefix regex to strip for tenant $side, e.g. ^SSD\s*-\s* (Enter for none)"
$sides += ,@($root, $label, $strip)
}
if(-not $sides) { continue }
$outputDir = Read-Host "Output directory for the comparison report"
if([string]::IsNullOrWhiteSpace($outputDir)) { Write-Host "Required." -ForegroundColor Red; continue }
$outputDir = [IO.Path]::GetFullPath(($outputDir.Trim().Trim('"',"'") -replace '^~', $HOME))
$pyArgs = @(
(Join-Path $projectRoot "Scripts/Compare-Tenants.py"),
"--root-a", $sides[0][0], "--label-a", $sides[0][1], "--strip-a", $sides[0][2],
"--root-b", $sides[1][0], "--label-b", $sides[1][1], "--strip-b", $sides[1][2],
"--output-dir", $outputDir
)
if((Read-Host "Compare assignments too? [y/N]") -like 'y*') { $pyArgs += "--include-assignments" }
if((Read-Host "Fuzzy name/content matching? [Y/n]") -like 'n*') { $pyArgs += "--no-fuzzy" }
Write-Host "`nComparing ..." -ForegroundColor Cyan
& $python.Source @pyArgs
Write-Host "`nPress any key to return to the menu..." -ForegroundColor DarkGray
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
continue
}
if($choiceNumber -eq 17)
{
$defaultBaseline = Join-Path $projectRoot "Baselines/CISM365-v7-Generated.yaml"