美文网首页
2021-11-15 PowerShell 7 多并发入门

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

作者: 硅谷少年 | 来源:发表于2021-11-15 09:42 被阅读0次

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 多并发入门

      本文链接:https://www.haomeiwen.com/subject/wvnftrtx.html