fix: Export-RdpRepairDiagnosticReport ломался на одном cert (foreach PS 5.1)
foreach по PSCustomObject перечисляет свойства, не cert — нужен @(). Рекурсивное flatten в Get-RdpRepairCertificateArray, самотест Export-паттерна. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -93,12 +93,16 @@ function Get-RdpRepairCertificateArray {
|
||||
param([object]$Certificates)
|
||||
if ($null -eq $Certificates) { return @() }
|
||||
$flat = New-Object System.Collections.Generic.List[object]
|
||||
foreach ($item in @($Certificates)) {
|
||||
$pending = New-Object System.Collections.Generic.Stack[object]
|
||||
foreach ($entry in @($Certificates)) { $pending.Push($entry) }
|
||||
while ($pending.Count -gt 0) {
|
||||
$item = $pending.Pop()
|
||||
if ($null -eq $item) { continue }
|
||||
if ($item -is [object[]]) {
|
||||
foreach ($inner in @($item)) {
|
||||
if ($null -ne $inner) { [void]$flat.Add($inner) }
|
||||
}
|
||||
} elseif ($null -ne $item) {
|
||||
foreach ($inner in @($item)) { $pending.Push($inner) }
|
||||
} elseif ($null -ne $item.PSObject.Properties['Thumbprint']) {
|
||||
[void]$flat.Add($item)
|
||||
} else {
|
||||
[void]$flat.Add($item)
|
||||
}
|
||||
}
|
||||
@@ -324,7 +328,7 @@ function Export-RdpRepairDiagnosticReport {
|
||||
$snap.PSObject.Properties | ForEach-Object {
|
||||
if ($_.Name -eq 'Certificates') {
|
||||
$lines += 'Certificates:'
|
||||
foreach ($c in (Get-RdpRepairCertificateArray $_.Value)) {
|
||||
foreach ($c in @(Get-RdpRepairCertificateArray $_.Value)) {
|
||||
$lines += (' - {0}; Thumb={1}; NotAfter={2}; Key={3}' -f $c.Subject, $c.Thumbprint, $c.NotAfter, $c.HasKey)
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user