locked
Paralel Excution RRS feed

  • Question

  • When I call a function in PS script, it has to wait until the function execution is done before continuing the rest. In Powershell, is there a way to call the function and then continuing without waiting. It is something like parallell processing? thanks.
    Thursday, June 11, 2020 3:26 PM

Answers

  • Powershell 7 has foreach-object -parallel.


    1..5 | foreach-object -parallel { sleep 5; get-date }

    Thursday, June 11, 2020 2:28:31 PM
    Thursday, June 11, 2020 2:28:31 PM
    Thursday, June 11, 2020 2:28:31 PM
    Thursday, June 11, 2020 2:28:31 PM
    Thursday, June 11, 2020 2:28:31 PM

    • Edited by JS2010 Thursday, June 11, 2020 6:29 PM
    • Marked as answer by Ian3 Thursday, June 11, 2020 6:49 PM
    Thursday, June 11, 2020 6:27 PM

All replies

  • You can run code in teh background as a job.

    help about_jobs


    \_(ツ)_/

    Thursday, June 11, 2020 4:05 PM
  • Powershell 7 has foreach-object -parallel.


    1..5 | foreach-object -parallel { sleep 5; get-date }

    Thursday, June 11, 2020 2:28:31 PM
    Thursday, June 11, 2020 2:28:31 PM
    Thursday, June 11, 2020 2:28:31 PM
    Thursday, June 11, 2020 2:28:31 PM
    Thursday, June 11, 2020 2:28:31 PM

    • Edited by JS2010 Thursday, June 11, 2020 6:29 PM
    • Marked as answer by Ian3 Thursday, June 11, 2020 6:49 PM
    Thursday, June 11, 2020 6:27 PM