Freeman
Freeman

Reputation: 5801

Is it possible to run multiple powershell scripts, in order, with waiting for completion before launching next?

I have 3 Powershell ISE scripts.

Script1.ps1, Script2.ps1, Script3.ps1

Is it possible to run all scripts, in the order given? When i am asking this i am not suggesting parallel behaviour, but rather a synchronious one. To execute script2, it must wait for script1 to finish, to execute script3 it must wait for script2 to finish, etc.

Cheers...

Upvotes: 1

Views: 5341

Answers (2)

E.V.I.L.
E.V.I.L.

Reputation: 2166

for($i=1;$i-le3;$i++){
    & ".\script$i.ps1"
    if(!$?){
         Write-Error "Script $i failed; Exiting"
         return (-1)
    }
}

$? returns true if the last command ran successfully.

Upvotes: 4

Vesper
Vesper

Reputation: 18747

.\script1.ps1
.\script2.ps1
.\stript3.ps1

All in a *.ps1 file that'll be started in PS by yourself.

Upvotes: 7

Related Questions