Загрузка данных


Stop-Service -Name TermService -Force -ErrorAction SilentlyContinue
Stop-Service -Name UmRdpService -Force -ErrorAction SilentlyContinue


$certs = Get-ChildItem -Path Cert:\LocalMachine\Remote Desktop\ -ErrorAction SilentlyContinue
if ($certs) {
    $certs | Remove-Item -Force
    Write-Host "Сертификаты RDP удалены: $($certs.Count) шт." -ForegroundColor Green
} else {
    Write-Host "Сертификатов в хранилище Remote Desktop не найдено." -ForegroundColor Yellow
}


$regPath = 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp'
if (Get-ItemProperty -Path $regPath -Name 'SSLCertificateSHA1Hash' -ErrorAction SilentlyContinue) {
    Remove-ItemProperty -Path $regPath -Name 'SSLCertificateSHA1Hash' -Force
    Write-Host "Ключ SSLCertificateSHA1Hash удалён из реестра." -ForegroundColor Green
} else {
    Write-Host "Ключ SSLCertificateSHA1Hash не найден (это нормально)." -ForegroundColor Yellow
}


$acl = Get-Acl -Path "C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys"
$acl.Access | Format-Table IdentityReference, FileSystemRights, AccessControlType


$acl = Get-Acl -Path "C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys"
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("NT AUTHORITY\SYSTEM","FullControl","ContainerInherit,ObjectInherit","None","Allow")
$acl.SetAccessRule($rule)
Set-Acl -Path "C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys" -AclObject $acl
Write-Host "Права SYSTEM восстановлены." -ForegroundColor Green


Start-Service -Name TermService
Start-Service -Name SessionEnv
Start-Service -Name UmRdpService


Start-Sleep -Seconds 5
Get-NetTCPConnection -LocalPort 3389 -ErrorAction SilentlyContinue | Format-Table LocalAddress, LocalPort, State, OwningProcess


Get-WinEvent -LogName 'Microsoft-Windows-TerminalServices-LocalSessionManager/Operational' -MaxEvents 5 | Format-List TimeCreated, Id, Message


sfc /scannow
DISM /Online /Cleanup-Image /RestoreHealth