首页 > 解决方案 > Powershell7 WinSCP New-WinSCPSession 异常

问题描述

我有一个现有的 Powershell 脚本,它在 PowerShell 5.1 中没有问题。安装 PowerShell 7 后,该脚本不再工作,并且在尝试建立 WinSCP 会话时失败。

首先,会话选项是通过 New-WinSCPSessionOption 创建的,并且这些选项会毫无问题地存储到 $sessionOption 中。

$sessionOption = New-WinSCPSessionOption -HostName $hostName -Credential $credentials -Protocol Ftp

当会话设置运行时,Powershell 7 中会引发异常:

$session = New-WinSCPSession -SessionOption $sessionOption

抛出以下异常:

Line |
 |      $session = New-WinSCPSession -SessionOption $sessionOption
 |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 | 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)'."

标签: powershellwinscpwinscp-net

解决方案


推荐阅读