6

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!

3
  • Do you need to run the two scripts in ISE? If yes: why?
    – Rob
    Apr 2, 2016 at 11:12
  • yes I do since they both load a local module...
    – M.T.
    Apr 2, 2016 at 11:16
  • you can load modules without ISE. link
    – Rob
    Apr 2, 2016 at 11:18

3 Answers 3

7

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.

5

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/

1
  • One should mention however, that not all cmdlets are supported in Workflows and figuring out why a script does not work as expected inside a workflow can be quite a pain in the *. Workflows are great nonetheless, but more fun if the code inside was developed with the thought "should-run-in-a-workflow" in mind.
    – Rob
    Apr 2, 2016 at 19:55
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.