Hidayath
Hidayath

Reputation: 374

Problem executing multiple powershell scripts from a batch file

I have a .bat that calls 3 PowerShell scripts Basically the bat file looks like this

PScript1
Pscript2
Pscript3

After the Pscript1 the batch file does not execute Pscript2 or Pscript3, it stops and does not seem to return control to the batch file. Does anyone know what might cause this problem ?

Upvotes: 1

Views: 4574

Answers (1)

Keith Hill
Keith Hill

Reputation: 201662

In a batch file you would typically use && or || depending on whether or not you wanted the subsequent commands to run based on the success of previous commands e.g.:

powershell.exe .\PScript1.ps1 && powershell.exe .\PScript2.ps1

This invocation would execute the following command only if the preceeding command succeeded. You also need to specify powershell.exe as the EXE. The default action for a .ps1 is to open the file for editing.

Upvotes: 5

Related Questions