Kick off a process and wait for the result

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

You can use Wait-Job. Wait-Job (Microsoft.PowerShell.Core) - PowerShell | Microsoft Docs

Thanks. If I understood that right I should be able to
$job = Start-Job -Scriptblock…
followed by
%job | Wait-Job

but it still just rolls on without waiting for the WinSCP process to finish.

I think I previously tried something similar but I’ve read so many suggestions ans tried so many options its becoming a bit of a blur.