Author Posts

July 20, 2017 at 4:22 pm

hello
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
#example
para(....)
......
......
if($folderID -eq '1')
{

& ".\copyjob.ps1"
& ".\Import.ps1"
}
else
{
& ".\copyjob.ps1"
invoke-command -computer $server -Filepath ".\Import.ps1"
}

July 20, 2017 at 5:20 pm

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

Test1.ps1:

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. https://www.youtube.com/watch?v=KprrLkjPq_c