Make PowerShell scripts wait there turn!

Welcome Forums General PowerShell Q&A Make PowerShell scripts wait there turn!

This topic contains 1 reply, has 2 voices, and was last updated by

Senior Moderator
2 months, 3 weeks ago.

  • Author
  • #166825

    Topics: 1
    Replies: 0
    Points: -8
    Rank: Member

    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

  • #166867

    Senior Moderator
    Topics: 8
    Replies: 1079
    Points: 3,621
    Helping Hand
    Rank: Community Hero

    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.


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

You must be logged in to reply to this topic.