I have ./main.ps1 that calls ./worker1.ps1 and worker2.ps1 with parameters, lines from main.ps1:
# other stuff in main script
$args = @()
$args += ("-PARAM1", "$VAR1")
$args += ("-PARAM2", "$VAR2")
$worker1 = "./workers/worker1.ps1"
Invoke-Expression "$worker1 $args" -ErrorAction Stop
# other stuff in main script
$worker2 = "./workers/worker2.ps1"
Invoke-Expression "$worker2 $args" -ErrorAction Stop
If worker1.ps1 fails it has exit 1 line,
The problem is that even when worker1.ps1 fails worker2.ps1 is called by main.ps1
How could I avoid that and fail main script as soon as one of the called fails?