none
ForEach-Object -Parallel in PS 7 RRS feed

  • Question

  • I got PS 7 installed and run (thanks Leon). And trying to test by following script. My purpose is to access each array element in each parallel process but not working. any other way to do that?

    $s = '111','222','aaa','bbb','ccc'
    0..4 | ForEach-Object -Parallel { $s[$_] }

    Cannot index into a null array.
    At line:1 char:2
    +  $s[$_]
    +  ~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

    Sunday, October 20, 2019 3:13 PM

Answers

  • Hi,

    Thanks for your question.

    Try to use $using: keyword to pass variable.

     0..4 | ForEach-Object -Parallel {$($using:s)[$_] }

    Best regards,

    Lee


    Just do it.

    • Marked as answer by Ian3 Wednesday, October 23, 2019 2:43 AM
    Monday, October 21, 2019 7:14 AM
    Moderator

All replies