fix: Thumbprint при одном cert после нативного сброса (PS 5.1 unwrap)
Добавлены Get-RdpRepairCertificateArray/FirstCertificate, самотесты на вложенные массивы; Fix-RdpTls больше не использует Select-Object -First 1 на cert. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -86,8 +86,30 @@ function Get-RdpRepairRemoteDesktopCertificates {
|
||||
} finally {
|
||||
$store.Close()
|
||||
}
|
||||
# Запятая перед return: иначе PS 5.1 разворачивает массив из одного cert и ломает .Count
|
||||
return ,[object[]]$list.ToArray()
|
||||
return [object[]]$list.ToArray()
|
||||
}
|
||||
|
||||
function Get-RdpRepairCertificateArray {
|
||||
param([object]$Certificates)
|
||||
if ($null -eq $Certificates) { return @() }
|
||||
$flat = New-Object System.Collections.Generic.List[object]
|
||||
foreach ($item in @($Certificates)) {
|
||||
if ($item -is [object[]]) {
|
||||
foreach ($inner in @($item)) {
|
||||
if ($null -ne $inner) { [void]$flat.Add($inner) }
|
||||
}
|
||||
} elseif ($null -ne $item) {
|
||||
[void]$flat.Add($item)
|
||||
}
|
||||
}
|
||||
return [object[]]$flat.ToArray()
|
||||
}
|
||||
|
||||
function Get-RdpRepairFirstCertificate {
|
||||
param([object]$Certificates)
|
||||
$arr = @(Get-RdpRepairCertificateArray -Certificates $Certificates)
|
||||
if ($arr.Count -lt 1) { return $null }
|
||||
return $arr[0]
|
||||
}
|
||||
|
||||
function Clear-RdpRepairCertificateStores {
|
||||
@@ -258,7 +280,7 @@ function Invoke-RdpRepairNativeReset {
|
||||
return [PSCustomObject]@{
|
||||
RebootScheduled = $false
|
||||
CertCount = $certs.Count
|
||||
Certificates = $certs
|
||||
Certificates = ,[object[]]$certs
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,7 +305,7 @@ function Get-RdpRepairDiagnosticSnapshot {
|
||||
TermService = (Get-Service TermService).Status
|
||||
RdpAllowed = -not (Get-ItemProperty $script:RdpRepairTsKey).fDenyTSConnections
|
||||
CertCount = $certs.Count
|
||||
Certificates = $certs
|
||||
Certificates = ,[object[]]$certs
|
||||
GpoLicenseSrv = $pol.LicenseServers
|
||||
GpoLicMode = $pol.LicensingMode
|
||||
Events1057_24h = $ev1057
|
||||
@@ -302,7 +324,7 @@ function Export-RdpRepairDiagnosticReport {
|
||||
$snap.PSObject.Properties | ForEach-Object {
|
||||
if ($_.Name -eq 'Certificates') {
|
||||
$lines += 'Certificates:'
|
||||
foreach ($c in $_.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