Make PowerShell scripts wait there turn!

I have created several ps1 scripts to install applications. When I run them manually one by one they work great both local and remote. When I try to automate all the individual scripts to run one after the other, they fail. They end up running over one another, not allowing one to finish before the next one starts.

So I thought why not take all the scripts and copy them into one ps1 file and try that. After modifying the variables the all in one script did work. However it gave me the same problem as before. The commands would start running before the previous command finished.

What I am asking is if anyone can give me a code snippet that I can use at the end or beginning of each ps1 script that will ensure that it checks and waits to ensure that no other code or application is running before it starts.

I am asking for a complete code snippet because I am like really, really, really, new to powershell as in I have only been using it for two weeks.

Thanks in advances

Going back your initial approach, how are you executing those scripts ? There are ways to wait for a program to complete before another starts in PowerShell.

Before all, If PowerShell is required for you at work, it’s a must to learn it and there are lots of resources for that. some important links below.

Video: Getting Started with PowerShell 3.0 | Microsoft Docs

Book: Learn PowerShell in a Month of Lunches (By Don Jones , is the best ever book to start PowerShell)