I am using .Net assembly with powershell commands, i am moving the files from server to local folder, everything is working fine, however i have some issue with the authentication, i want to use my Private key instead of using public key fingerprint, this worked fine in command scripting, but in powershell i get the error message. "SessionOptions.Protocol is Protocol.Sftp or Protocol.Scp, but SessionOptions.HostKey is not set." The code works when i mention the public key finger print, Below is the sample code, can anyone post any example to just use Private key location.
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
$sessionOptions.HostName = "host.net"
$sessionOptions.UserName = "userName"
$sessionOptions.SshHostKeyFingerprint = "ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
$session = New-Object WinSCP.Session
$session.ExecutablePath = "C:\Program Files (x86)\WinSCP\winscp.exe"
#all the file transfer operations