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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容