M.T.
M.T.

Reputation: 71

How to run multiple Powershell Scripts at the same time?

so I have two .ps1 scripts that check for new Tasks every 60 seconds and I want to run them at the same time. I use them every day and starting them gets a little annoying. Ideally, I want to write a script that I can run that runs those two for me.

The Problem is that as they don't stop at some point, I can't just start them one after the other and I can't find a command to open a new PS ISE instance. However, one instance can't run both scripts at the same time. The Ctrl+T Option would be perfect, but I can't find the equivalent command.

Does anyone have an idea on how to solve this? Thanks!

Upvotes: 7

Views: 42375

Answers (3)

collapseh
collapseh

Reputation: 21

Use CTRL+T to create a new powershell instance (a tab is created, which is called powershell 2, I believe) inside Powershell ISE.

From the new Powershell tab you can now open a second powershell script and run it aside the script running in other powershell tabs.

Upvotes: 2

Balthazar
Balthazar

Reputation: 493

If you have Powershell 3.0+ you could use workflows. they are similar to functions, but have the advantage that you can run commands parallel.

so your workflow would be something like this:

workflow RunScripts {
    parallel {
        InlineScript { C:\myscript.ps1 }   
        InlineScript { C:\myotherscript.ps1 }
    }
}

keep in mind that a workflow behaves like a function. so it needs to be loaded into the cache first, and then called by running the RunScripts command.

more information: https://blogs.technet.microsoft.com/heyscriptingguy/2013/01/09/powershell-workflows-nesting/

Upvotes: 5

restless1987
restless1987

Reputation: 1598

I think what you want is something like

Start-Process Powershell.exe -Argumentlist "-file C:\myscript.ps1"
Start-Process Powershell.exe -Argumentlist "-file C:\myscript2.ps1"

In addition to that: Use Import-Module $Modulepath inside the scripts to ensure the availability of the modules.

Upvotes: 7

Related Questions