Write-Host "Cleaning RDP history..." -ForegroundColor Cyan # Delete registry entries reg delete "HKCU\Software\Microsoft\Terminal Server Client\Default" /va /f 2>$null reg delete "HKCU\Software\Microsoft\Terminal Server Client\Servers" /f 2>$null # Delete saved credentials $creds = cmdkey /list | Select-String "TERMSRV" foreach ($cred in $creds) { $name = $cred.ToString().Trim().Split("=")[-1] cmdkey /delete:$name 2>$null } # Delete .rdp files Get-ChildItem "$env:USERPROFILE\Documents\*.rdp" -Force -ErrorAction SilentlyContinue | Remove-Item -Force Get-ChildItem "$env:USERPROFILE\Desktop\*.rdp" -Force -ErrorAction SilentlyContinue | Remove-Item -Force Get-ChildItem "$env:APPDATA\Microsoft\Windows\Recent\*.rdp" -Force -ErrorAction SilentlyContinue | Remove-Item -Force Write-Host "" Write-Host "--- Verification ---" -ForegroundColor Yellow # Check registry Default $default = reg query "HKCU\Software\Microsoft\Terminal Server Client\Default" 2>$null | Select-String "MRU" if ($default) { Write-Host "[FAIL] Address history still exists:" -ForegroundColor Red $default | ForEach-Object { Write-Host " $_" } } else { Write-Host "[OK] Address history is clear" -ForegroundColor Green } # Check registry Servers $servers = reg query "HKCU\Software\Microsoft\Terminal Server Client\Servers" 2>$null if ($servers -match "REG_") { Write-Host "[FAIL] Server entries still exist" -ForegroundColor Red } else { Write-Host "[OK] Server entries are clear" -ForegroundColor Green } # Check credentials $remainingCreds = cmdkey /list | Select-String "TERMSRV" if ($remainingCreds) { Write-Host "[FAIL] Saved credentials still exist:" -ForegroundColor Red $remainingCreds | ForEach-Object { Write-Host " $_" } } else { Write-Host "[OK] Saved credentials are clear" -ForegroundColor Green } # Check .rdp files $rdpFiles = @( Get-ChildItem "$env:USERPROFILE\Documents\*.rdp" -Force -ErrorAction SilentlyContinue Get-ChildItem "$env:USERPROFILE\Desktop\*.rdp" -Force -ErrorAction SilentlyContinue Get-ChildItem "$env:APPDATA\Microsoft\Windows\Recent\*.rdp" -Force -ErrorAction SilentlyContinue ) if ($rdpFiles.Count -gt 0) { Write-Host "[FAIL] RDP files still exist:" -ForegroundColor Red $rdpFiles | ForEach-Object { Write-Host " $($_.FullName)" } } else { Write-Host "[OK] No RDP files found" -ForegroundColor Green } Write-Host "" Write-Host "Done. Press any key to close..." -ForegroundColor Cyan $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")