I’m running a script as a scheduled task and I want it to invoke WinSCP, wait for it to complete and then continue depending on the result but no matter what I try it seems to just roll straight on. I’m currently having to rely on a Start-Sleep line to just make it wait but I would prefer it to actually work!
This is my current attempt:
$job = Start-Job -ScriptBlock { C:"Program Files (x86)"\WinSCP\WinSCP.exe /ini=nul /nointeractiveinput /log=‘E:\Path\to\Log\File\WinSCPLog.txt’ /script=‘E:\Path\to\WinSCP\Script\WinSCP.txt’ }
Receive-Job -Wait $job
I read elsewhere about using ‘-PassThru’ and/or ‘-NoNewWindow’ but neither are accepted in this version.
I did use a ‘Start-Job’ without the ‘-ScriptBlock’ option which would accept ‘-PassThru’ but still didn’t wait.
I’ve tried running it using ‘&’ and $LASTEXITCODE.
I’ve tried ‘Start-Job’ with ‘-File’ and ‘-Arguments’ portions.
I’ve tried a ‘$job.WaitforExit()’ construction.
There’s probably a couple of other goes I’ve had that I’ve forgotten.
I’m using Powershell 4.0 on Windows Server 2012R2
What am I missing? Thanks for any clues