chain multiple function

i have a long script and two successives scripts nested inside, copyjob.ps1 and Import.ps1 and i want to run the second one Import.ps1 only if the first one Import.ps1 succeed with no error

if($folderID -eq ‘1’)

& “.\copyjob.ps1”
& “.\Import.ps1”
& “.\copyjob.ps1”
invoke-command -computer $server -Filepath “.\Import.ps1”

You need your scripts to return something to trigger on. For example


return $true

Then in the controller script, get something to capture that output

$Check = test1.ps1
if ($check){ do stuff }

I would think about turning those scripts into functions with good outputs you can trigger on as well. Check out Don Jones’ series on powershell tool making.