Closed rik-e closed 4 months ago
im not exactly sure what is going on, but its referencing a different install of the WinSCP.exe in your Program Files directory. I ship the matching exe to the dll in the module path, and I tell the session to use that binary specifically, see https://github.com/tomohulk/WinSCP/blob/45c2940b38cf6c46ab57dee7c1a08821fd7cd416/WinSCP/Public/New-WinSCPSession.ps1#L81.
do you maybe have the WinSCP client running at the same time?
The Client is not running.
We use Scriptrunner to schedule Powershell Scripts. This is why $PSScriptRoot seems to be not working. After I uninstalled WinSCP directly the error changes:
Write-Error: Exception calling "Open" with "1" argument(s): "The winscp.exe executable was not found at location of the
assembly WinSCPnet (C:\Program Files\WindowsPowerShell\Modules\WinSCP\6.3.2.0\lib\net40), nor the entry assembly SRXPSHo
st (C:\Program Files\ScriptRunner\Service\Bin\WinPS), nor in an installation path. You may use Session.ExecutablePath pr
operty to explicitly set path to winscp.exe." (NotSpecified: (:) [Write-Error], WriteErrorException)
Exception calling "Open" with "1" argument(s): "The winscp.exe executable was not found at location of the assembly WinS
CPnet (C:\Program Files\WindowsPowerShell\Modules\WinSCP\6.3.2.0\lib\net40), nor the entry assembly SRXPSHost (C:\Progra
m Files\ScriptRunner\Service\Bin\WinPS), nor in an installation path. You may use Session.ExecutablePath property to exp
licitly set path to winscp.exe."
As I get it there are three options:
ill have to think about this for a little bit, to me this feels like an issue with Script Runner and not the WinSCP module.
I was able to get around this like that:
$exe_path = (Get-Module WinSCP).ModuleBase + "\bin\WinSCP.exe"
$Session = New-Object WinSCP.Session
$Session.ExecutablePath = $exe_path
$SessionOptions = New-Object WinSCP.SessionOptions
...
This would avoid the need to adjust the module.
I added two parameters to New-WinSCPSession
, DisableVersionCheck
so you don't have to have matching versions of the dll and exe. And ExecutablePath
, this allows you to specify a full path to the .exe. Can you test this out in your PSScriptRunner and see if it works for your situation? You'll have to download the source code here, I haven't pushed it to the gallery yet. I also updated the WinSCP Core from 6.3.2 to 6.3.3. Please let me know how it works out, and I'll push it to the PSGallery. Thanks.
sorry for all those commits, trying to work out some dynamic mapping of parameters to properties, but its all good now, please let me know if this works for you're situation. Thanks!
The test is scheduled for tomorrow. I'll let you know the result.
I was able to use New-WinSCPSession -DisableVersionCheck $true without any error. Looks good to me.
Thanks, all my tests are passing the updated module has been published to the PSGallery.
Issue Description
Write-Error: Exception calling "Open" with "1" argument(s): "The version of C:\Program Files (x86)\WinSCP\winscp.exe (6. 3.3.0) does not match version of this assembly C:\Program Files\WindowsPowerShell\Modules\WinSCP\6.3.2.0\lib\net40\WinSC Pnet.dll (6.3.2.0)." (NotSpecified: (:) [Write-Error], WriteErrorException) Exception calling "Open" with "1" argument(s): "The version of C:\Program Files (x86)\WinSCP\winscp.exe (6.3.3.0) does n ot match version of this assembly C:\Program Files\WindowsPowerShell\Modules\WinSCP\6.3.2.0\lib\net40\WinSCPnet.dll (6.3 .2.0)."
Example
Expected Output
Connection is established. Newer Version of the module is missing.
Actual Output
See Issue description
WinSCP-PowerShell Version
Environment
Windows Server 2019 Datacenter
Name : ConsoleHost Version : 5.1.17763.5696 InstanceId : c99acbd0-8249-4011-8a17-d5c96ab0a5ad UI : System.Management.Automation.Internal.Host.InternalHostUserInterface CurrentCulture : de-DE CurrentUICulture : en-US PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy DebuggerEnabled : True IsRunspacePushed : False Runspace : System.Management.Automation.Runspaces.LocalRunspace