fix: корректный .Count при одном RDP-сертификате в store
PowerShell 5.1 разворачивал одноэлементные коллекции cert и ломал диагностику. Добавлены самотест и обновлён README (-IncludeAdminTests, обход GPO). Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -66,7 +66,7 @@ try {
|
||||
|
||||
if ($RestoreTls) {
|
||||
Write-RdpRepairLog 'Возврат SecurityLayer=2 (TLS)' 'STEP' $logPath
|
||||
$certs = Get-RdpRepairRemoteDesktopCertificates
|
||||
$certs = @(Get-RdpRepairRemoteDesktopCertificates)
|
||||
if ($certs.Count -eq 0) {
|
||||
Write-RdpRepairLog 'No cert in Remote Desktop store - run full repair or repair install first' 'ERROR' $logPath
|
||||
exit 2
|
||||
|
||||
@@ -67,10 +67,15 @@ Assert-Test 'Initialize-RdpRepairDataRoot returns path' {
|
||||
}
|
||||
|
||||
Assert-Test 'Get-RdpRepairComputerDnsNames non-empty' {
|
||||
$n = Get-RdpRepairComputerDnsNames
|
||||
$n = @(Get-RdpRepairComputerDnsNames)
|
||||
if ($n.Count -lt 1) { throw 'no dns names' }
|
||||
}
|
||||
|
||||
Assert-Test 'Get-RdpRepairRemoteDesktopCertificates exposes Count' {
|
||||
$certs = @(Get-RdpRepairRemoteDesktopCertificates)
|
||||
$null = $certs.Count
|
||||
}
|
||||
|
||||
Assert-Test 'Get-RdpRepairDiagnosticSnapshot object shape' {
|
||||
if (-not (Test-RdpRepairIsAdministrator)) {
|
||||
Write-Host ' (skip snapshot fields - not admin)' -ForegroundColor DarkYellow
|
||||
|
||||
@@ -86,7 +86,8 @@ function Get-RdpRepairRemoteDesktopCertificates {
|
||||
} finally {
|
||||
$store.Close()
|
||||
}
|
||||
return $list
|
||||
# Запятая перед return: иначе PS 5.1 разворачивает массив из одного cert и ломает .Count
|
||||
return ,[object[]]$list.ToArray()
|
||||
}
|
||||
|
||||
function Clear-RdpRepairCertificateStores {
|
||||
@@ -253,7 +254,7 @@ function Invoke-RdpRepairNativeReset {
|
||||
}
|
||||
Start-Service TermService -ErrorAction SilentlyContinue
|
||||
Start-Sleep -Seconds 5
|
||||
$certs = Get-RdpRepairRemoteDesktopCertificates
|
||||
$certs = @(Get-RdpRepairRemoteDesktopCertificates)
|
||||
return [PSCustomObject]@{
|
||||
RebootScheduled = $false
|
||||
CertCount = $certs.Count
|
||||
@@ -265,7 +266,7 @@ function Get-RdpRepairDiagnosticSnapshot {
|
||||
$polPath = 'HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services'
|
||||
$pol = if (Test-Path $polPath) { Get-ItemProperty $polPath -ErrorAction SilentlyContinue } else { $null }
|
||||
$fips = (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Lsa\FipsAlgorithmPolicy' -Name Enabled -ErrorAction SilentlyContinue).Enabled
|
||||
$certs = Get-RdpRepairRemoteDesktopCertificates
|
||||
$certs = @(Get-RdpRepairRemoteDesktopCertificates)
|
||||
$ev1057 = @(Get-WinEvent -FilterHashtable @{
|
||||
LogName = 'System'
|
||||
Id = 1057, 36870
|
||||
|
||||
Reference in New Issue
Block a user