feat(compare): offer a drift check after the full tenant export
After menu item 23 finishes it offers to compare with the newest earlier export of the same tenant (assignments included) and writes the report to <root>/_drift/<old>-to-<new>/. Compare-Tenants.py now also accepts a folder that holds a single export folder (e.g. a dated folder containing Exports/).
This commit is contained in:
+25
-1
@@ -537,7 +537,31 @@ while($true)
|
||||
if($SettingsFile) { $exportParams.SettingsFile = $SettingsFile }
|
||||
& (Join-Path $projectRoot "Scripts/Start-HeadlessIntune.ps1") @exportParams
|
||||
Write-Host "`nExport finished: $exportPath" -ForegroundColor Cyan
|
||||
Write-Host "Tip: compare with an earlier export of this tenant using menu item 22 (leave the prefix blank to see drift)." -ForegroundColor DarkGray
|
||||
|
||||
# Drift check against the newest earlier export of this tenant in the same root
|
||||
$python = Get-Command python3 -ErrorAction SilentlyContinue
|
||||
if(-not $python) { $python = Get-Command python -ErrorAction SilentlyContinue }
|
||||
$prev = Get-ChildItem -LiteralPath $root -Directory -ErrorAction SilentlyContinue |
|
||||
Where-Object { $_.Name -like "$safeName-*" -and $_.FullName -ne $exportPath } |
|
||||
Sort-Object LastWriteTime -Descending | Select-Object -First 1
|
||||
if($python -and (Test-Path -LiteralPath $exportPath -PathType Container))
|
||||
{
|
||||
$prevPath = if($prev) { $prev.FullName } else { $null }
|
||||
$hint = if($prevPath) { "Enter = $($prev.Name)" } else { "path to an earlier export, Enter to skip" }
|
||||
$ans = Read-Host "`nCompare with an earlier export to see drift? ($hint, n = skip)"
|
||||
if($ans -like 'n') { $prevPath = $null }
|
||||
elseif(-not [string]::IsNullOrWhiteSpace($ans)) { $prevPath = [IO.Path]::GetFullPath(($ans.Trim().Trim('"',"'") -replace '^~', $HOME)) }
|
||||
if($prevPath -and (Test-Path -LiteralPath $prevPath -PathType Container))
|
||||
{
|
||||
$prevName = Split-Path $prevPath -Leaf
|
||||
$curName = Split-Path $exportPath -Leaf
|
||||
$driftDir = Join-Path (Join-Path $root "_drift") "$prevName-to-$curName"
|
||||
& $python.Source (Join-Path $projectRoot "Scripts/Compare-Tenants.py") `
|
||||
--root-a $prevPath --label-a $prevName --root-b $exportPath --label-b $curName `
|
||||
--include-assignments --output-dir $driftDir
|
||||
Write-Host "Drift report: $(Join-Path $driftDir 'tenant-comparison.md')" -ForegroundColor Cyan
|
||||
}
|
||||
}
|
||||
Write-Host "`nPress any key to return to the menu..." -ForegroundColor DarkGray
|
||||
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user