none
ForEach-Object -Parallel in PS 7 RRS feed

  • السؤال

  • 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

    21/صفر/1441 03:13 م

الإجابات

  • 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.

    • تم وضع علامة كإجابة بواسطة Ian3 24/صفر/1441 02:43 ص
    22/صفر/1441 07:14 ص
    المشرف

جميع الردود