从 SSIS 执行的 PowerShell 脚本引用 WinSCP.exe

Reference WinSCP.exe from PowerShell script executed from SSIS

我正在尝试从 SSIS 中执行 PowerShell 脚本。我的脚本以 Add-Type -Path "WinSCPnet.dll" 开头,它出错了,因为它无法在包含我的 PowerShell 脚本的文件夹中找到 WinSCP.exe。来发现服务器管理员没有将 WinSCP 安装到 GAC 中。这是我的问题吗?
如果是这样,我如何以及在哪里可以使用 $session.ExecutablePath 在我的脚本中引用 WinSCP.exe?任何 help/direction 将不胜感激。谢谢。

下面是我的脚本:

# Load WinSCP .NET assembly
Add-Type -Path "WinSCPnet.dll"

# Declare variables 
$date = Get-Date
$dateStr = $date.ToString("yyyyMMdd")
#$fileDirectory = "\abicfs2\apps\CoverageVerifier\"
#$filePath = "\abicfs2\apps\CoverageVerifier\cvgver." + $dateStr + ".0101"
$filePath = "\empqaapp1\coverageverifier_scripts\CoverageVerifier\cvgver.20190121.0101"

# Write-Output $filePath

# Set up session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
    Protocol = [WinSCP.Protocol]::Sftp
    HostName = "secureftp.iso.com"
    UserName = "account"
    Password = "password"
    SshHostKeyFingerprint = "ssh-rsa 2048 8C1lwAjxCNRF6B4kbPIeW52/GB+98FmLMt0AJNf/Sf4="
}

#$sessionOptions.AddRawSettings("FSProtocol", "2")

$session = New-Object WinSCP.Session 
# $session.SessionLogPath = "\share\apps\CoverageVerifier\UploadLog.log" 


try
{
    # Connect
    $session.Open($sessionOptions)

    # Transfer files
    $session.PutFiles($filePath,"/").Check()
}
finally
{
    $session.Dispose()
}

WinSCP程序集安装说明摘录(https://winscp.net/eng/docs/library_install):

The package includes the assembly itself (winscpnet.dll) and a required dependency, WinSCP executable winscp.exe.

The binaries interact with each other and must be kept in the same folder for the assembly to work. In rare situations this is not possible (e.g. when installing the assembly to GAC), make use of the Session.ExecutablePath property to force the assembly to look for the winscp.exe in a different location.

I am trying to execute a Powershell script from within SSIS

您似乎认为您需要在 GAC 中安装 WinSCP .NET 程序集,以便您可以从从 SSIS 执行的 PowerShell 脚本中执行它。我不认为这是真的。仅当您直接从 SSIS 代码中使用它时,您才需要 GAC 中的程序集。什么不是你的情况。

您只需将 WinSCPnet.dllWinSCP.exe 存储到您的 PowerShell 脚本目录即可。


无论如何回答你的问题:

If so, how and where can I reference the WinSCP.exe in my script using $session.ExecutablePath?

$session = New-Object WinSCP.Session 
$session.ExecutablePath = "C:\path\WinSCP.exe"

(但按照上面的说法,我认为你不需要它)


Come to find out the server admin did NOT install WinSCP into the GAC.

您无法将 .exe 文件安装到 GAC。