Policies: Vergleich als zweispaltige Gegenüberstellung (A | B)

Statt gestapelter JSON-Blöcke jetzt eine Tabelle: pro settingDefinitionId eine
Zeile mit Wert A neben Wert B. Kompakter, lesbarer Kurzwert (Get-SettingDisplayValue:
Choice/Simple/Collections) im Vordergrund, volles kanonisches JSON als Tooltip.
Status-Einfärbung (unterschiedlich/nur A/nur B/gleich) + Filter "nur Unterschiede".
Endpoint liefert dafür vereinheitlichte rows (Union der Keys) mit short/full je Seite.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
marcoandClaude Opus 4.8 committed 2026-10-19 13:31:25 +02:00
1 parent e35005e489
commit 19e479a08d
3 files changed
+116 -64

No files matched your search

+64 -23
View File
@@ -1121,9 +1121,42 @@ function Invoke-PolicyConsolidateEndpoint {
# ============================================================
# Zwei Settings-Catalog-Policies vergleichen (Diff nach settingDefinitionId)
# ============================================================
# Body: { ids:[idA, idB] }. Liefert: nur in A / nur in B / gleich / unterschiedlich.
# Nutzt dieselbe Extraktion wie die Konsolidierung (Get-SettingDefinitionId +
# Get-SettingCanonicalJson -> kanonischer Wert-Vergleich).
# Kompakter, lesbarer Wert einer settingInstance (fuer die Gegenueberstellung).
# Best-effort: Choice -> letzte Wert-Komponente, Simple -> Wert, Collections -> Liste/Anzahl.
# Das volle (kanonische) JSON bleibt separat erhalten.
function Get-SettingDisplayValue {
param($SettingElement)
$si = Get-PolicyProp $SettingElement 'settingInstance'
if (-not $si) { $si = $SettingElement }
$cv = Get-PolicyProp $si 'choiceSettingValue'
if ($cv) {
$v = [string](Get-PolicyProp $cv 'value')
$tail = ($v -split '_')[-1]
$kids = @(Get-PolicyProp $cv 'children') | Where-Object { $_ }
if (@($kids).Count -gt 0) { return "$tail (+$(@($kids).Count) Unter)" }
return $tail
}
$sv = Get-PolicyProp $si 'simpleSettingValue'
if ($sv) { return [string](Get-PolicyProp $sv 'value') }
$scv = @(Get-PolicyProp $si 'simpleSettingCollectionValue') | Where-Object { $_ }
if (@($scv).Count -gt 0) {
$joined = (@($scv | ForEach-Object { [string](Get-PolicyProp $_ 'value') }) -join ', ')
if ($joined.Length -gt 140) { $joined = $joined.Substring(0, 137) + '...' }
return $joined
}
$ccv = @(Get-PolicyProp $si 'choiceSettingCollectionValue') | Where-Object { $_ }
if (@($ccv).Count -gt 0) {
return (@($ccv | ForEach-Object { ([string](Get-PolicyProp $_ 'value') -split '_')[-1] }) -join ', ')
}
$gcv = @(Get-PolicyProp $si 'groupSettingCollectionValue') | Where-Object { $_ }
if (@($gcv).Count -gt 0) { return "$(@($gcv).Count) Gruppe(n)" }
return ''
}
# Body: { ids:[idA, idB] }. Liefert A/B-Metadaten + vereinheitlichte Zeilen (Union
# der settingDefinitionId), jede mit Status (same|different|onlyA|onlyB) sowie
# Kurzwert und vollem (kanonischem) Wert je Seite - fuer die Gegenueberstellung.
function Invoke-PolicyCompareEndpoint {
param($Body)
try { Assert-GraphConnected } catch { return @{ __status = 401; error = 'Nicht mit Microsoft Graph verbunden' } }
@@ -1141,7 +1174,7 @@ function Invoke-PolicyCompareEndpoint {
if (-not $el) { continue }
$defId = Get-SettingDefinitionId $el
if (-not $defId) { continue }
$map[$defId] = Get-SettingCanonicalJson $el
$map[$defId] = @{ canon = Get-SettingCanonicalJson $el; short = Get-SettingDisplayValue $el }
}
$pols += @{
id = [string]$id
@@ -1153,28 +1186,36 @@ function Invoke-PolicyCompareEndpoint {
}
$a = $pols[0]; $b = $pols[1]
$onlyA = @(); $onlyB = @(); $same = @(); $different = @()
foreach ($k in @($a.map.Keys)) {
if ($b.map.Contains($k)) {
if ($a.map[$k] -eq $b.map[$k]) { $same += @{ settingDefinitionId = $k; value = $a.map[$k] } }
else { $different += @{ settingDefinitionId = $k; valueA = $a.map[$k]; valueB = $b.map[$k] } }
} else {
$onlyA += @{ settingDefinitionId = $k; value = $a.map[$k] }
}
}
foreach ($k in @($b.map.Keys)) {
if (-not $a.map.Contains($k)) { $onlyB += @{ settingDefinitionId = $k; value = $b.map[$k] } }
# Union der Keys: A-Reihenfolge, dann die nur in B vorhandenen anhaengen.
$keys = [System.Collections.Generic.List[string]]::new()
foreach ($k in @($a.map.Keys)) { [void]$keys.Add([string]$k) }
foreach ($k in @($b.map.Keys)) { if (-not $a.map.Contains($k)) { [void]$keys.Add([string]$k) } }
$rows = @()
$cDiff = 0; $cOnlyA = 0; $cOnlyB = 0; $cSame = 0
foreach ($k in $keys) {
$inA = $a.map.Contains($k); $inB = $b.map.Contains($k)
$ea = $null; $eb = $null
if ($inA) { $ea = $a.map[$k] }
if ($inB) { $eb = $b.map[$k] }
$status = ''
if ($inA -and $inB) {
if ($ea.canon -eq $eb.canon) { $status = 'same'; $cSame++ } else { $status = 'different'; $cDiff++ }
} elseif ($inA) { $status = 'onlyA'; $cOnlyA++ } else { $status = 'onlyB'; $cOnlyB++ }
$row = [ordered]@{ id = $k; status = $status }
if ($inA) { $row['shortA'] = $ea.short; $row['fullA'] = $ea.canon }
if ($inB) { $row['shortB'] = $eb.short; $row['fullB'] = $eb.canon }
$rows += $row
}
return @{
ok = $true
a = @{ id = $a.id; name = $a.name; platform = $a.platform; count = $a.count }
b = @{ id = $b.id; name = $b.name; platform = $b.platform; count = $b.count }
onlyA = @($onlyA)
onlyB = @($onlyB)
same = @($same)
different = @($different)
counts = @{ onlyA = @($onlyA).Count; onlyB = @($onlyB).Count; same = @($same).Count; different = @($different).Count }
ok = $true
a = @{ id = $a.id; name = $a.name; platform = $a.platform; count = $a.count }
b = @{ id = $b.id; name = $b.name; platform = $b.platform; count = $b.count }
rows = @($rows)
counts = @{ different = $cDiff; onlyA = $cOnlyA; onlyB = $cOnlyB; same = $cSame }
}
}