Powershell in Administrator mode
I had a similar issue, then realised it was down to running PowerShell as an Administrator.
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
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: (:) [New-Object], COMException
+ FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
C:\Windows\system32\WinSCPnet.dll
?
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