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

StackOverflow https://stackoverflow.com/questions/15545964

Question

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...

Était-ce utile?

La solution

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

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

Autres conseils

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top