Figured it out
Right – so the issue for me is I had the value enclosed in quotes and this won't pass validation for the fingerprint.
SshHostKeyFingerprint
. I can use my SshHostKeyFingerprint
value hard-coded in the script and it works fine, so this proves it isn't an issue with the actual value (which is what the above answer implies).
New-Object : The specified value is invalid, or the property is read-only. Change the value and repeat the operation.
function getCreds(){
$creds=[PSCustomObject]@{
hostname = ''
username = ''
pwd = ''
fingerprint = ''
}
$creds.hostname = 'xxxx'
$creds.username = 'xxxx'
$creds.pwd = 'xxxx'
$creds.fingerprint = 'ssh-rsa 1024 xxxx'
return $creds
}
function transferFile($creds){
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
HostName = $creds.hostname
UserName = $creds.username
Password = $creds.pwd
SshHostKeyFingerprint = $creds.fingerprint
}
}
$creds=getCreds()
transferFile($creds)