• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 38
  • Last Modified:

Powershell script to run after first script completes.

I have two scripts and i need other should run when first script execution is completed.

is there any way i can do that ? I tried to merge both the scripts in single script but both are running simultaneously.
0
Chirag Nagrekar
Asked:
Chirag Nagrekar
1 Solution
 
zvitamConsultantCommented:
Let's say you have two scripts one is  C:\Users\User\Desktop\Scripts\1.ps1 and the is called C:\Users\User\Desktop\Scripts\2.ps1 and you want these two scripts to run one after the other.

Create a third script let's call it Master.ps1:

As follows:

&"C:\Users\User\Desktop\Scripts\1.ps1"
&"C:\Users\User\Desktop\Scripts\1.ps2"

now run Master.ps1

Hope that helps,
Zvitam.
0
 
Chirag NagrekarSystem AnalystAuthor Commented:
I tried the same but both scripts run in parallel.
0
 
Jose Gabriel Ortega CCEO J0rt3g4 Consulting ServicesCommented:
Show your scripts so we can actually see why is running that way?
what do the scripts do?

Jose
0
Worried about phishing attacks?

90% of attacks start with a phish. It’s critical that IT admins and MSSPs have the right security in place to protect their end users from these phishing attacks. Check out our latest feature brief for tips and tricks to keep your employees off a hackers line!

 
Chirag NagrekarSystem AnalystAuthor Commented:
Hi Zvitam,

Your script worked. Sorry i was missing '&' sign in master script.

Thanks.
1
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
That is nonsense. The ampersand operator does not change the way the scripts are executed, so there is no difference between above and
C:\Users\User\Desktop\Scripts\1.ps1
C:\Users\User\Desktop\Scripts\1.ps2

Open in new window

There has to be something else amd special about your scripts, and as said the above cannot be the solution.
Of course the example is obviously wrong and should be
&"C:\Users\User\Desktop\Scripts\1.ps1"
&"C:\Users\User\Desktop\Scripts\2.ps1"

Open in new window


if anything ;-)
0
 
Chirag NagrekarSystem AnalystAuthor Commented:
I had different scenario. can't mention that one here as its too long. But earlier i was using

Start-Process powershell.exe -ArgumentList "-file abc.ps1"
Start-Process powershell.exe -ArgumentList "-file xyz.ps1"
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
That's something you do only if you want the processes in parallel intentionally (or have other reasons like running with a different user account). But you can still use Start-Process if you add -Wait, if you prefer that.
Whatsoever, the accepted answer is not correct as being "the" solution, and that is the point.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now