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.
LVL 3
Chirag NagrekarSystem AnalystAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Chirag NagrekarSystem AnalystAuthor Commented:
I tried the same but both scripts run in parallel.
0
Jose Gabriel Ortega CastroCEOCommented:
Show your scripts so we can actually see why is running that way?
what do the scripts do?

Jose
0
Redefine Your Security with AI & Machine Learning

The implications of AI and machine learning in cyber security are massive and constantly growing, creating both efficiencies and new challenges across the board. Check out our on-demand webinar to learn more about how AI can help your organization!

Chirag NagrekarSystem AnalystAuthor Commented:
Hi Zvitam,

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

Thanks.
1
Qlemo"Batchelor", 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
Qlemo"Batchelor", 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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.