Policies: Vergleich zweier Settings-Catalog-Policies (Diff)
Neuer Button "Vergleichen" (aktiv bei genau 2 Settings-Catalog-Policies) + Endpoint POST /api/policies/compare. Diff nach settingDefinitionId über die vorhandene Extraktion (Get-SettingDefinitionId/Get-SettingCanonicalJson): nur in A / nur in B / gleich / unterschiedlich (Werte gegenübergestellt). Modal mit Zählern + Abschnitten, Diff als JSON exportierbar. Read-only. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
40e26b9f32
commit
e35005e489
5 files changed
+202
-3
No files matched your search
@@ -1118,6 +1118,66 @@ 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).
|
||||
function Invoke-PolicyCompareEndpoint {
|
||||
param($Body)
|
||||
try { Assert-GraphConnected } catch { return @{ __status = 401; error = 'Nicht mit Microsoft Graph verbunden' } }
|
||||
|
||||
$ids = @(Get-PolicyProp $Body 'ids') | Where-Object { $_ }
|
||||
if (@($ids).Count -ne 2) { return @{ __status = 400; error = 'Bitte genau zwei Settings-Catalog-Policies auswaehlen.' } }
|
||||
|
||||
$pols = @()
|
||||
foreach ($id in $ids) {
|
||||
$detail = $null
|
||||
try { $detail = Get-GraphPolicyDetail -Type 'settingscatalog' -Id ([string]$id) } catch {}
|
||||
if (-not $detail) { return @{ __status = 400; error = "Policy $id konnte nicht geladen werden (nur Settings Catalog wird unterstuetzt)." } }
|
||||
$map = [ordered]@{}
|
||||
foreach ($el in @(Get-PolicyProp $detail 'settings')) {
|
||||
if (-not $el) { continue }
|
||||
$defId = Get-SettingDefinitionId $el
|
||||
if (-not $defId) { continue }
|
||||
$map[$defId] = Get-SettingCanonicalJson $el
|
||||
}
|
||||
$pols += @{
|
||||
id = [string]$id
|
||||
name = [string](Get-PolicyProp $detail 'name')
|
||||
platform = [string](Get-PolicyProp $detail 'platforms')
|
||||
map = $map
|
||||
count = $map.Count
|
||||
}
|
||||
}
|
||||
|
||||
$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] } }
|
||||
}
|
||||
|
||||
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 }
|
||||
}
|
||||
}
|
||||
|
||||
# ============================================================
|
||||
# Policy-Snapshot nach Git (voller Export, stabile Dateinamen)
|
||||
# ============================================================
|
||||
|
||||
Reference in new issue
Block a user