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个例子练习下就能上手了。
使用手册:
参数:
-Parallel
-ThrottleLimit
-TimeoutSeconds parameter takes an integer that specifies the maximum time to wait for completion before the command is aborted
-AsJob
网友评论