Need a Powershell script

Hello Experts,

I need help to get this script converted to Powershell or VBS script, I have winscp that connects to a remote directory and synchronize files. I don't have to even synchronize but I just want to establish the connection, below is the script.

I downloaded the winscpnet.dll as per the WinSCP site , this will work with powershell. Below is the batchfile that I want to convert to powershell.

option batch abort
option confirm off
open sftp://sftpuser04:password123! -hostkey="ssh-rsa 2048 d5:71:6a:0d:60:99:23:c4:63:18:55:54:5a:fb:79:05"
synchronize both C:\Temp\Target /home/sftpuser04/Source

Thank you
SR ZakNetwork Solutions Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dustin SaundersDirector of OperationsCommented:
The website has examples:

$ErrorActionPreference = 'Stop'
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"

$session = [WinSCP.Session]::new()

$config = New-Object -TypeName WinSCP.SessionOptions -Property @{
    Protocol   = [WinSCP.Protocol]::Sftp
    HostName   = ''
    UserName   = 'sftpusername'
    Password   = 'password'
    PortNumber = 6969
    SshHostKeyFingerprint = 'ssh-rsa 2048 d5:71:6a:0d:60:99:23:c4:63:18:55:54:5a:fb:79:05'


$transferOptions = New-Object -TypeName WinSCP.TransferOptions -Property @{
    TransferMode = [WinSCP.TransferMode]::Binary


Open in new window

More on converting batch to Powershell:

More Powershell examples:
SR ZakNetwork Solutions Author Commented:
My issue is how to make the script work when my home location and is using UNC path ?
Jose Gabriel Ortega CastroCEOCommented:
I don't think that's actually a problem just try it on powershell on your computer and report back if you are having issues.

C:\Temp\Target /home/sftpuser04/Source

C:\Temp\Target  UPN

If that doesn't work you would need to use local addresses.
Defend Against the Q2 Top Security Threats

Were you aware that overall malware worldwide was down a surprising 42% from Q1'18? Every quarter, the WatchGuard Threat Lab releases an Internet Security Report that analyzes the top threat trends impacting companies worldwide. Learn more by viewing our on-demand webinar today!

SR ZakNetwork Solutions Author Commented:
I am getting this error, do you know what I need to change on it.

Method invocation failed because [WinSCP.Session] does not contain a method named 'new'.
At C:\Script\Script3.ps1:4 char:1
+ $session = [WinSCP.Session]::new()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MethodNotFound
SR ZakNetwork Solutions Author Commented:
The template provided on winscp do not seem to work.
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
You need to run a New-Object for the session object instead of the new() method.
$session = New-Object WinSCP.Session

Open in new window

Dustin SaundersDirector of OperationsCommented:
What version of the DLL do you have?  Could be older/missing a method.  The sample code works fine for me:

(Ignore the $sessuib part, that was a typo)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.