$ErrorActionPreference = "Stop"
$key = Join-Path $env:USERPROFILE ".ssh\id_ed25519_cnperp"
$pass = "casmic123"
try {
    Set-Service ssh-agent -StartupType Manual -ErrorAction SilentlyContinue
    Start-Service ssh-agent -ErrorAction SilentlyContinue
} catch {}
$psi = New-Object System.Diagnostics.ProcessStartInfo
$psi.FileName = "ssh-add"
$psi.Arguments = "`"$key`""
$psi.UseShellExecute = $false
$psi.RedirectStandardInput = $true
$psi.RedirectStandardOutput = $true
$psi.RedirectStandardError = $true
$p = [System.Diagnostics.Process]::Start($psi)
$p.StandardInput.WriteLine($pass)
$p.StandardInput.Close() | Out-Null
if (-not $p.WaitForExit(15000)) { $p.Kill(); throw "ssh-add timed out" }
Write-Host "ssh-add exit: $($p.ExitCode)"
Write-Host $p.StandardOutput.ReadToEnd()
$err = $p.StandardError.ReadToEnd()
if ($err) { Write-Host $err }
if ($p.ExitCode -ne 0) { exit $p.ExitCode }
ssh-add -l
