Problem using WinSCPnet.dll inPowerShell, when in a CLASS [includes screen capture]
I am having a problem using WinSCPnet.dll with PowerShell, in both ISE and VS2015.
I am running Windows 10, PowerShell V5 (version 5 build 10586 revision 122)
I have the WinSCPnet.dll file in two places, the
I am using classes within my PowerShell script, which is where WinSCP is not being recognized.
The references to WinSCP within the class fail.
* the references to
When I run the script within ISE, I get this:
Within ISE I can "fix" this by typing the command within the script pane: * to update the RED underlines I have to edit something within the code
Within VS2015 community edition, I am stuck. I can't get it to acknowledge WinSCP at all.
I checked my DLL's, and they are not blocked. I registered the DLL and that didn't change anything. I want to stress that WinSCP is working for me outside of a CLASS. Within ISE, if I manually
What can I do to fix this, and how can I get this PowerShell script to work within VS?
I am running Windows 10, PowerShell V5 (version 5 build 10586 revision 122)
I have the WinSCPnet.dll file in two places, the
program files (x86)
and in the script directory.
I am using classes within my PowerShell script, which is where WinSCP is not being recognized.
The references to WinSCP within the class fail.
My script looks like this:Unable to find type [WinSCP.Protocol]
$ScriptPath = $(Split-Path -Parent $MyInvocation.MyCommand.Definition) [Reflection.Assembly]::LoadFrom( $(Join-Path $ScriptPath "WinSCPnet.dll") ) | Out-Null sessionOptions1 = New-Object WinSCP.SessionOptions -Property @{ Protocol = [WinSCP.Protocol]::ftp FtpMode = [WinSCP.FtpMode]::Active } Class Ftp { Ftp() { sessionOptions2 = New-Object WinSCP.SessionOptions -Property @{ Protocol = [WinSCP.Protocol]::Sftp FtpMode = [WinSCP.FtpMode]::Active } } }
[WinSCP.Protocol]
and [WinSCP.FtpModel]
within the class
both underlined in RED. (see attachment)
When I run the script within ISE, I get this:
PS D:\> D:\testFTP.ps1 At D:\testFTP.ps1:14 char:29 + Protocol = [WinSCP.Protocol]::Sftp + ~~~~~~~~~~~~~~~ Unable to find type [WinSCP.Protocol]. At D:\testFTP.ps1:15 char:28 + FtpMode = [WinSCP.FtpMode]::Active + ~~~~~~~~~~~~~~ Unable to find type [WinSCP.FtpMode]. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : TypeNotFound
add-type -Path 'C:\Program Files (x86)\WinSCP\WinSCPnet.dll'
Within VS2015 community edition, I am stuck. I can't get it to acknowledge WinSCP at all.
I checked my DLL's, and they are not blocked. I registered the DLL and that didn't change anything. I want to stress that WinSCP is working for me outside of a CLASS. Within ISE, if I manually
Add-Type
to it, then WinSCP will work within a CLASS. This work around does not work with VS though.
What can I do to fix this, and how can I get this PowerShell script to work within VS?