fix: корректный .Count при одном RDP-сертификате в store

PowerShell 5.1 разворачивал одноэлементные коллекции cert и ломал диагностику.
Добавлены самотест и обновлён README (-IncludeAdminTests, обход GPO).

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
PTah
2026-06-12 20:25:00 +10:00
parent 14348a0181
commit 60b843b936
4 changed files with 19 additions and 7 deletions
+8 -2
View File
@@ -15,10 +15,16 @@ Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force
cd C:\path\to\fix-DAK-PC\scripts cd C:\path\to\fix-DAK-PC\scripts
``` ```
4. **Самотесты** (обязательно): 4. **Самотесты** (обязательно, с правами администратора):
```powershell ```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. **Полный интерактивный ремонт**: 5. **Полный интерактивный ремонт**:
+1 -1
View File
@@ -66,7 +66,7 @@ try {
if ($RestoreTls) { if ($RestoreTls) {
Write-RdpRepairLog 'Возврат SecurityLayer=2 (TLS)' 'STEP' $logPath Write-RdpRepairLog 'Возврат SecurityLayer=2 (TLS)' 'STEP' $logPath
$certs = Get-RdpRepairRemoteDesktopCertificates $certs = @(Get-RdpRepairRemoteDesktopCertificates)
if ($certs.Count -eq 0) { if ($certs.Count -eq 0) {
Write-RdpRepairLog 'No cert in Remote Desktop store - run full repair or repair install first' 'ERROR' $logPath Write-RdpRepairLog 'No cert in Remote Desktop store - run full repair or repair install first' 'ERROR' $logPath
exit 2 exit 2
+6 -1
View File
@@ -67,10 +67,15 @@ Assert-Test 'Initialize-RdpRepairDataRoot returns path' {
} }
Assert-Test 'Get-RdpRepairComputerDnsNames non-empty' { Assert-Test 'Get-RdpRepairComputerDnsNames non-empty' {
$n = Get-RdpRepairComputerDnsNames $n = @(Get-RdpRepairComputerDnsNames)
if ($n.Count -lt 1) { throw 'no dns names' } 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' { Assert-Test 'Get-RdpRepairDiagnosticSnapshot object shape' {
if (-not (Test-RdpRepairIsAdministrator)) { if (-not (Test-RdpRepairIsAdministrator)) {
Write-Host ' (skip snapshot fields - not admin)' -ForegroundColor DarkYellow Write-Host ' (skip snapshot fields - not admin)' -ForegroundColor DarkYellow
+4 -3
View File
@@ -86,7 +86,8 @@ function Get-RdpRepairRemoteDesktopCertificates {
} finally { } finally {
$store.Close() $store.Close()
} }
return $list # Запятая перед return: иначе PS 5.1 разворачивает массив из одного cert и ломает .Count
return ,[object[]]$list.ToArray()
} }
function Clear-RdpRepairCertificateStores { function Clear-RdpRepairCertificateStores {
@@ -253,7 +254,7 @@ function Invoke-RdpRepairNativeReset {
} }
Start-Service TermService -ErrorAction SilentlyContinue Start-Service TermService -ErrorAction SilentlyContinue
Start-Sleep -Seconds 5 Start-Sleep -Seconds 5
$certs = Get-RdpRepairRemoteDesktopCertificates $certs = @(Get-RdpRepairRemoteDesktopCertificates)
return [PSCustomObject]@{ return [PSCustomObject]@{
RebootScheduled = $false RebootScheduled = $false
CertCount = $certs.Count CertCount = $certs.Count
@@ -265,7 +266,7 @@ function Get-RdpRepairDiagnosticSnapshot {
$polPath = 'HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services' $polPath = 'HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services'
$pol = if (Test-Path $polPath) { Get-ItemProperty $polPath -ErrorAction SilentlyContinue } else { $null } $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 $fips = (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Lsa\FipsAlgorithmPolicy' -Name Enabled -ErrorAction SilentlyContinue).Enabled
$certs = Get-RdpRepairRemoteDesktopCertificates $certs = @(Get-RdpRepairRemoteDesktopCertificates)
$ev1057 = @(Get-WinEvent -FilterHashtable @{ $ev1057 = @(Get-WinEvent -FilterHashtable @{
LogName = 'System' LogName = 'System'
Id = 1057, 36870 Id = 1057, 36870