gpt4 book ai didi

powershell - 并行中的Powershell调用命令不起作用

转载 作者:行者123 更新时间:2023-12-03 00:22:27 35 4
gpt4 key购买 nike

我正在尝试documentation中指定的一个非常简单的PowerShell Parallel示例。

1..5 | ForEach-Object -Parallel { "Hello $_"; sleep 1; } -ThrottleLimit 5 

但是它给出了以下错误,在这方面的任何帮助都将是适当的。
ForEach-Object : Parameter set cannot be resolved using the specified named parameters.
At C:\temp\parallel.ps1:2 char:9
+ 1..10 | ForEach-Object -Parallel {
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : MetadataError: (:) [ForEach-Object], ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.ForEachObjectCommand

以下是我的PowerShell版本信息
Name                           Value
---- -----
PSVersion 5.1.18362.752
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.18362.752
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

最佳答案

PowerShell 7.0中已引入ForEach-Object -Parallel。您正在使用PowerShell 5.1。这就是为什么它不起作用。

如果并行安装了PowerShell 7.0(可能的话),请直接调用PS可执行文件并执行该脚本。

关于powershell - 并行中的Powershell调用命令不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61956045/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com