Joey Joey - 3 months ago 12
PowerShell Question

Invoking psftp using powershell

My powershell code does not work when invoking PSFTP commands:

current code:

invoke-expression "psftp.exe -i key.ppk ubuntu@remoteserver -be b sftpcommands.txt > logs.log"


I have tried the following:

invoke-command "psftp.exe -i key.ppk ubuntu@remoteserver -be b sftpcommands.txt > logs.log"


and this

Start-Process -Wait -FilePath "psftp.exe -i key.ppk ubuntu@remoteserver -be b sftpcommands.txt > logs.log"


Running this in cmd prompt without the use of powershell works fine

psftp.exe -i key.ppk ubuntu@remoteserver -be b sftpcommands.txt > logs.log

Answer

I ended up restructuring my code to:

invoke-expression (.\psftp.exe 'remoteserver' -l 'ubuntu' -i key.ppk -v -b 'sftpcommands.txt' > 'logs.log') 2> $null