$connect_host=localhost
$connect_port=22

$fingerprints = ssh -o BatchMode=yes -p $connect_port $host "ssh-keygen -l -E sha256 -f /etc/ssh/ssh_host_ed25519_key.pub || ssh-keygen -l -E sha256 -f /etc/ssh/ssh_host_rsa_key.pub" | Select-String -Pattern "SHA256:[+/=a-zA-0-9]+" | % {$_.Matches.Value}

if ($LASTEXITCODE -ne 0)
{
    throw "Exit code $LASTEXITCODE"
}

if ($fingerprints.Count -ne 1)
{
    throw "Fingerprint not found"
}

winscp.exe sftp://${connect_host}:${connect_port} /hostkey=$fingerprints
