From 60b843b93626dc392c176f839f344013d806b9f9 Mon Sep 17 00:00:00 2001 From: PTah Date: Fri, 12 Jun 2026 20:25:00 +1000 Subject: [PATCH] =?UTF-8?q?fix:=20=D0=BA=D0=BE=D1=80=D1=80=D0=B5=D0=BA?= =?UTF-8?q?=D1=82=D0=BD=D1=8B=D0=B9=20.Count=20=D0=BF=D1=80=D0=B8=20=D0=BE?= =?UTF-8?q?=D0=B4=D0=BD=D0=BE=D0=BC=20RDP-=D1=81=D0=B5=D1=80=D1=82=D0=B8?= =?UTF-8?q?=D1=84=D0=B8=D0=BA=D0=B0=D1=82=D0=B5=20=D0=B2=20store?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PowerShell 5.1 разворачивал одноэлементные коллекции cert и ломал диагностику. Добавлены самотест и обновлён README (-IncludeAdminTests, обход GPO). Co-authored-by: Cursor --- README.md | 10 ++++++++-- scripts/Fix-RdpTls.ps1 | 2 +- scripts/Invoke-RdpRepairSelfTest.ps1 | 7 ++++++- scripts/lib/RdpRepair.Common.ps1 | 7 ++++--- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 43774cf..5944d50 100644 --- a/README.md +++ b/README.md @@ -15,10 +15,16 @@ Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force cd C:\path\to\fix-DAK-PC\scripts ``` -4. **Самотесты** (обязательно): +4. **Самотесты** (обязательно, с правами администратора): ```powershell -.\Invoke-RdpRepairSelfTest.ps1 +.\Invoke-RdpRepairSelfTest.ps1 -IncludeAdminTests +``` + +Ожидание: `FAIL=0`. Если `Set-ExecutionPolicy` ругается на GPO — для сессии достаточно `Process=Bypass` или запуск: + +```powershell +powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\Invoke-RdpRepairSelfTest.ps1 -IncludeAdminTests ``` 5. **Полный интерактивный ремонт**: diff --git a/scripts/Fix-RdpTls.ps1 b/scripts/Fix-RdpTls.ps1 index 83b21b4..2cae616 100644 --- a/scripts/Fix-RdpTls.ps1 +++ b/scripts/Fix-RdpTls.ps1 @@ -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 diff --git a/scripts/Invoke-RdpRepairSelfTest.ps1 b/scripts/Invoke-RdpRepairSelfTest.ps1 index 0f856ba..fc6beca 100644 --- a/scripts/Invoke-RdpRepairSelfTest.ps1 +++ b/scripts/Invoke-RdpRepairSelfTest.ps1 @@ -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 diff --git a/scripts/lib/RdpRepair.Common.ps1 b/scripts/lib/RdpRepair.Common.ps1 index 246e30b..28eeb09 100644 --- a/scripts/lib/RdpRepair.Common.ps1 +++ b/scripts/lib/RdpRepair.Common.ps1 @@ -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