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 }