From 40e26b9f322edf381238c3adf8c0dc766314b1e3 Mon Sep 17 00:00:00 2001 From: Marco Wende Date: Wed, 23 Sep 2026 13:29:40 +0200 Subject: [PATCH] Policies: ADMX-Presentation-Matching Hashtable-Bug behoben (PS7/Container) Where-Object liefert bei einem Treffer ein Einzelobjekt. Ist das eine Hashtable (PS7 ConvertFrom-Json -AsHashtable, wie im Docker-Container), war $sameType[0] eine Schluessel-Suche nach Key 0 (=> $null) statt Array-Index -> Presentation wurde als "nicht zuordenbar" gewertet und die Einstellung uebersprungen. Unter Windows PowerShell 5.1 (PSCustomObjects) trat der Fehler nicht auf. Fix: Where-Object-Ergebnis vor dem Indexieren in @() zwingen. Verifiziert per Simulation gegen die realen Firefox-ADMX-Exportdaten (Default Search Engine, URL for Home page). Co-Authored-By: Claude Opus 4.8 --- src/PolicyIO.ps1 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/PolicyIO.ps1 b/src/PolicyIO.ps1 index 03623bb..447fd80 100644 --- a/src/PolicyIO.ps1 +++ b/src/PolicyIO.ps1 @@ -538,14 +538,18 @@ function Resolve-TargetPresentationId { } | Select-Object -First 1 if ($m) { return [string](Get-PolicyProp $m 'id') } } - # 2) i-te Ziel-Presentation gleichen Typs (in Reihenfolge) + # 2) i-te Ziel-Presentation gleichen Typs (in Reihenfolge). + # WICHTIG: Ergebnis in @() zwingen - bei EINEM Treffer liefert Where-Object ein + # Einzelobjekt; ist das eine Hashtable (PS7 -AsHashtable), waere $x[0] eine + # Schluessel-Suche nach Key 0 (=> $null) statt Array-Index -> Fehlmatch. $idx = 0; if ($Counter.ContainsKey($srcType)) { $idx = [int]$Counter[$srcType] } - $sameType = @($TargetPres) | Where-Object { (& $norm (Get-PolicyProp $_ '@odata.type')) -eq $srcType } + $sameType = @(@($TargetPres) | Where-Object { (& $norm (Get-PolicyProp $_ '@odata.type')) -eq $srcType }) $Counter[$srcType] = $idx + 1 - if ($idx -lt @($sameType).Count) { return [string](Get-PolicyProp $sameType[$idx] 'id') } + if ($idx -lt $sameType.Count) { return [string](Get-PolicyProp $sameType[$idx] 'id') } # 3) Letzter Fallback: hat die Ziel-Definition genau EINE Presentation, nimm sie # (deckt Ein-Feld-Settings wie Textboxen zuverlaessig ab). - if (@($TargetPres).Count -eq 1) { return [string](Get-PolicyProp $TargetPres[0] 'id') } + $allTgt = @($TargetPres) + if ($allTgt.Count -eq 1) { return [string](Get-PolicyProp $allTgt[0] 'id') } return $null }