none
ForEach-Object -Parallel in PS 7 RRS feed

  • Dotaz

  • 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

    neděle 20. října 2019 15:13

Odpovědi

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

    • Označen jako odpověď Ian3 středa 23. října 2019 2:43
    pondělí 21. října 2019 7:14
    Moderátor

Všechny reakce