Why are options provided to WinSCP .NET assembly methods in PowerShell being ignored?

You are probably passing the options in a wrong order. Particularly, you cannot skip parameters, even if you do not need to use them.

For example, you want to call Session.PutFiles method and you provide the TransferOptions options parameter. The options is 4th parameter. Even though the 3rd bool remove parameter is optional and you are not interested in giving it a non-default value, you have to (PowerShell does not support passing values to optional parameters by name).

This is the correct call:

$session.PutFiles($localPath, $remotePath, $False, $options)

While this is wrong:

$session.PutFiles($localPath, $remotePath, $options)

PowerShell unfortunately does everything it can, to convert an invalid argument to a target parameter type. In this case, it will convert non-null $options argument to $True, instead of failing.

Last modified: by martin