2021-11-15 PowerShell 7 多并发入门

PowerShell 7 新增并发参数

| ForEach-Object -Parallel

例子:

-1
get-content ip.txt |foreach-object -Parallel{ ping.exe $_ }

-2
Get-Content /powershell/ip.txt |ForEach-Object -Parallel {if (Test-Connection -Count 1 -TargetName $_ -Quiet) {$_} } 6>$null

-3

$a = 1..100
$a | ForEach-Object -ThrottleLimit 5  -Parallel {
Write-Host $_
Start-Sleep -Seconds 3
}

这3个例子练习下就能上手了。

使用手册:

RFC0044-ForEach-Parallel-Cmdlet.md

参数:

-Parallel
-ThrottleLimit
-TimeoutSeconds parameter takes an integer that specifies the maximum time to wait for completion before the command is aborted
-AsJob

你可能感兴趣的:(2021-11-15 PowerShell 7 多并发入门)