【问题标题】:Pass variables to nested Foreach-Object in parallel PowerShell 7.1在并行 PowerShell 7.1 中将变量传递给嵌套的 Foreach-Object
【发布时间】:2022-07-07 20:11:32
【问题描述】:

所以我可以看到,将变量传递给嵌套的 for 循环存在如下所述的限制。如果我真的想将变量从外部传递到嵌套的 for 循环,还有其他解决方法吗?

另外,这个限制在 PS 7.2 中是否不再存在?

# to be used in a nested foreach parallel scriptblock.
$test1 = 'TestA'
1..2 | Foreach-Object -Parallel {
    $using:test1
    $test2 = 'TestB'
    1..2 | Foreach-Object -Parallel {
        $using:test2
    }
}

Line |
   2 |  1..2 | Foreach-Object -Parallel {
     |         ~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The value of the using variable '$using:test2' cannot be retrieved because it has not been set in the local session.```

【问题讨论】:

  • 在 PS 7.2 中为我工作。

标签: powershell parallel.foreach


【解决方案1】:

也许这会有所帮助:

https://github.com/PowerShell/PowerShell/issues/11817

应该像上面提到的那样工作!

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多