I'm new to using the PowerShell .Net Assembly, so there is likely a misunderstanding on my part.
I generated PowerShell .Net Assebly code from WinSCP, when I try to use it, I get an error. What am I doing wrong please?
CODE:
# Load WinSCP .NET assembly
Add-Type -Path "WinSCPnet.dll"
# Set up session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
HostName = "sftp site"
UserName = "username"
Password = "`password"
SshHostKeyFingerprint = "securitydata"
}
$sessionOptions.AddRawSettings("FSProtocol", "2")
$session = New-Object WinSCP.Session
try
{
# Connect
$session.Open($sessionOptions)
Write-Host $session
# Set up transfer options
$transferOptions = New-Object WinSCP.TransferOptions -Property @{
TransferMode = [WinSCP.TransferMode]::Ascii
}
# Transfer files
#changed
}
finally
{
$session.Dispose()
}
ERROR:
MethodInvocationException: untitled:Untitled-3:19:5
Line |
19 | $session.Open($sessionOptions)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Exception calling "Open" with "1" argument(s): "Method not found: 'Void System.Threading.EventWaitHandle..ctor(Boolean, System.Threading.EventResetMode, System.String, Boolean ByRef,
| System.Security.AccessControl.EventWaitHandleSecurity)'."