首页/系统/Windows 运维速查/批量并发执行与限流

批量并发执行与限流

Invoke-Command 并发受 ThrottleLimit 控制;本机并行任务用 ForEach-Object -Parallel(PowerShell 7+);都需要控制对目标的压力。

Windows 运维速查系统更新于 2026-10-12
用途规模化执行与负载控制
远程Invoke-Command -ThrottleLimit 32(默认)
本机并行ForEach-Object -Parallel -ThrottleLimit(PS7+)

常用示例

常用示例
$hosts = 1..50 | ForEach-Object { "node$_" }
Invoke-Command -ComputerName $hosts -ThrottleLimit 10 -ScriptBlock { Get-Service WinRM | Select-Object Status }
# PowerShell 7 本机并行
1..10 | ForEach-Object -Parallel { Start-Sleep -Seconds 1; $_ } -ThrottleLimit 5
对生产系统做变更要“先限流后提速”:小批量成功→评估→分批推进。

易错点

  • 并发过高会压垮目标或域控认证(登录风暴)
  • ForEach-Object -Parallel 变量需用 $using: 传参,作用域与串行版不同

数据来源与参考

  • Microsoft Learn:Invoke-Command ThrottleLimit
  • Microsoft Learn:ForEach-Object -Parallel

相关工具

​‌‌​​‌​​​‌‌​‌‌‌‌​‌‌​​​‌‌​‌‌‌​​‌‌​​‌​‌‌‌​​‌‌‌​​​‌​‌‌​‌​​‌​‌‌‌​​​‌​‌‌​‌​​‌​‌‌​​​‌‌​‌‌‌​‌​​​‌‌​‌‌‌‌​​‌​‌‌‌​​‌‌​​​‌‌​‌‌​‌‌‌‌​‌‌​‌‌​‌