You can use this snippet to retrieve an SSH host key fingerprint, suitable for usage with the winscp.com
file transfer utility. You can copy/paste the function into your own script and use it that way.
You can use it from the command line like this:
PS C:\Users\User\Desktop> function Get-SshFingerprint {
>> param( [string]$ssh_server )
>>
>> # Load WinSCP .NET assembly
>> Add-Type -Path "${env:ProgramFiles(x86)}\WinSCP\WinSCPnet.dll"
>>
>> # Setup session options
>> $sessionOptions = New-Object WinSCP.SessionOptions -Property @{
>> Protocol = [WinSCP.Protocol]::Sftp
>> HostName = $ssh_server
>> UserName = ""
>> }
>>
>> # Scan for the host key
>> $session = New-Object WinSCP.Session
>> try
>> {
>> $fingerprint = $session.ScanFingerprint($sessionOptions, "SHA-256")
>> }
>> finally
>> {
>> $session.Dispose()
>> }
>>
>> # And output the host key to the pipeline
>> Write-Output $fingerprint
>> }
PS C:\Users\User\Desktop> Get-SshFingerprint github.com
ssh-rsa 2048 nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8=