diff --git a/src/Api.ps1 b/src/Api.ps1
index d9ee017..72a90fe 100644
--- a/src/Api.ps1
+++ b/src/Api.ps1
@@ -60,6 +60,7 @@ function Invoke-ApiHandler {
"POST /api/policies/import" { return Import-PoliciesEndpoint -Body $Body }
"POST /api/policies/assign" { return Invoke-PolicyAssignEndpoint -Body $Body }
"POST /api/policies/consolidate" { return Invoke-PolicyConsolidateEndpoint -Body $Body }
+ "POST /api/policies/compare" { return Invoke-PolicyCompareEndpoint -Body $Body }
"POST /api/policies/git-snapshot" { return Invoke-PolicyGitSnapshotEndpoint }
"POST /api/pickfolder" { return Invoke-FolderPickerEndpoint -Body $Body }
diff --git a/src/PolicyIO.ps1 b/src/PolicyIO.ps1
index 447fd80..efa2746 100644
--- a/src/PolicyIO.ps1
+++ b/src/PolicyIO.ps1
@@ -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)
# ============================================================
diff --git a/www/app.js b/www/app.js
index e7418d5..fc68c8b 100644
--- a/www/app.js
+++ b/www/app.js
@@ -6426,14 +6426,24 @@ function polUpdateSelCount() {
if (c) c.textContent = n;
}
// Konsolidieren nur bei >=2 Policies UND alle vom Typ Settings Catalog.
+ const allSc = keys.every(k => k.startsWith('settingscatalog::'));
const btnC = document.getElementById('btnPolConsolidate');
if (btnC) {
- const allSc = n >= 2 && keys.every(k => k.startsWith('settingscatalog::'));
- btnC.disabled = !allSc;
- btnC.title = allSc
+ const ok = n >= 2 && allSc;
+ btnC.disabled = !ok;
+ btnC.title = ok
? 'Ausgewählte Settings-Catalog-Policies zu einer neuen Policy zusammenführen'
: 'Mindestens zwei Policies vom Typ „Settings Catalog" auswählen';
}
+ // Vergleichen: genau 2 Settings-Catalog-Policies.
+ const btnCmp = document.getElementById('btnPolCompare');
+ if (btnCmp) {
+ const ok = n === 2 && allSc;
+ btnCmp.disabled = !ok;
+ btnCmp.title = ok
+ ? 'Die zwei ausgewählten Settings-Catalog-Policies vergleichen'
+ : 'Genau zwei Policies vom Typ „Settings Catalog" auswählen';
+ }
}
function polSyncCheckAll() {
@@ -6605,6 +6615,88 @@ async function polDoConsolidate() {
document.getElementById('btnPolConsolidate')?.addEventListener('click', openPolConsolidate);
document.getElementById('polConsConfirm')?.addEventListener('click', polDoConsolidate);
+// =============================================================
+// Policies vergleichen (zwei Settings-Catalog-Policies -> Diff)
+// =============================================================
+let _polCmpResult = null;
+
+async function openPolCompare() {
+ const keys = [...PolState.selected].filter(k => k.startsWith('settingscatalog::'));
+ if (keys.length !== 2) { toast('Genau zwei Settings-Catalog-Policies auswählen.', 'warn'); return; }
+ const ids = keys.map(k => k.slice('settingscatalog::'.length));
+ _polCmpResult = null;
+ document.getElementById('polCmpSummary').innerHTML = ' Vergleiche…';
+ document.getElementById('polCmpBody').innerHTML = '';
+ document.getElementById('polCmpInfo').textContent = '';
+ openModal('modalPolCompare');
+ try {
+ const res = await api('/api/policies/compare', { method: 'POST', body: { ids }, timeoutMs: 120000 });
+ _polCmpResult = res;
+ renderPolCompare(res);
+ } catch (e) {
+ document.getElementById('polCmpSummary').innerHTML = `Vergleich fehlgeschlagen: ${escapeHtml(e.message)}`;
+ }
+}
+
+// settingDefinitionId lesbarer machen: letztes Segment hervorheben.
+function polCmpShortId(id) {
+ const s = String(id || '');
+ const tail = s.split(/[_~\.]/).filter(Boolean).pop() || s;
+ return `${escapeHtml(tail)} ${escapeHtml(s)}`;
+}
+
+function polCmpVal(v) {
+ return `${escapeHtml(String(v ?? ''))}`;
+}
+
+function renderPolCompare(res) {
+ const c = res.counts || {};
+ document.getElementById('polCmpSummary').innerHTML =
+ `