chain multiple function

This topic contains 1 reply, has 2 voices, and was last updated by  LuisrOrta 3 months ago.

  • Author
    Posts
  • #75343

    bin
    Participant

    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"
    }

  • #75346

    LuisrOrta
    Participant

    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

You must be logged in to reply to this topic.