I am trying to load the WinSCP .DLL into a script so that I can use various attributes/Methods from the library. I am struggling because the example on the WinSCP site results in a "TypeNotFound" error when you actually try to use it. So far I have tried and failed to create a module/manifest to do so, and am now trying to simply load the DLL in a script and then load that script in my main script (because apparently this makes sense in PowerShell..?) I have been referred to this answer by Takophiliac, but This answer is not verbose enough for me and I assume some others to follow.
Please can someone just show me a simple example of loading a DLL library so that I can use the various attributes/methods in my main script without getting "TypeNotFound" errors? Please.
Edit: adding example
[void] CreateSession() {
try {
# Load WinSCP .NET assembly
Add-Type -Path (Join-Path $PSScriptRoot "\winscp\WinSCPnet.dll")
# Setup session options
$this.sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
The issue is that [WinSCP.Protocol] causes a parsing error, as [WinSCP.Protocol] is apparently not known at parsing time? I dont understand how anyone really uses the example where they just use Add-Type, because after doing that you still get "TypeNotFound" errors everywhere you try to use the attributes/methods of the library.