Topic "Add-type in Powershell not working"

Author Message
bmcnish
[View user's profile]

Joined: 2014-02-25
Posts: 10
I have installed WinSCP v.5.7.7. in C:\Program Files (x86)\WinSCP\ and unlocked the WinSCPNet.dll as documented, but when I enter Add-Type -Path "WinSCPnet.dll" in Powershell it still fails:

Add-Type : Could not load file or assembly 'file:///C:\Windows\system32\WinSCPnet.dll' or one of its
dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
At line:1 char:1
+ Add-Type -Path "WinSCPnet.dll"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-Type], FileLoadException
+ FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.AddTypeComma
nd

This is a new Windows 2012R2 server. I need this to work as I have to convert all of my VBS scripts that call WinSCP to Powershell scripts ASAP.
Advertisements
martin◆
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 27082
Location: Prague, Czechia
Why are you loading the assembly from C:\Windows\system32\WinSCPnet.dll?

Show us your code!
bmcnish
[View user's profile]

Joined: 2014-02-25
Posts: 10
I found the correct syntax:
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
bmcnish
[View user's profile]

Joined: 2014-02-25
Posts: 10
I unblocked the DLL and this is what I get when I attempt to run the PS1 script:

Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
$sessionOptions = New-Object -ComObject WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
HostName = "myserver"
UserName = "myuser"
Password = "mypassword"
SshHostKeyFingerprint = "ssh-rsa 2048 fc:44:00:23:f2:8a:aa:00:64:f2:d8:36:4c:2e:6d:f1"
}

New-Object : Retrieving the COM class factory for component with CLSID {2D4EF368-EE80-4C15-AE77-D12AEAF4B00A} failed due to the following error:
80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
At line:19 char:19
+ $sessionOptions = New-Object -ComObject WinSCP.SessionOptions -Property @{
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (Smile [New-Object], COMException
+ FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand
martin◆
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 27082
Location: Prague, Czechia
Why do you instantiate the class via COM? The WinSCP .NET assembly is a native .NET assembly (as the name says). Instantiate the class directly, as all the examples show:
https://winscp.net/eng/docs/library_powershell

Or have the WinSCP GUI generate a code template for you:
https://winscp.net/eng/docs/ui_generateurl#code
Advertisements

You can post new topics in this forum

Search

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License