我想使用PowerShell工作流快速对多台计算机执行ping操作。但是对于我的团队来说,我的脚本运行缓慢,因为我的脚本需要11分钟才能ping通5000台PC。
我在Windows Server 2012 R2上。
workflow OnlinePC {
Param ($srv)
$collectionWithItems = New-Object System.Collections.ArrayList
foreach -parallel -throttlelimit 5500 ($pc in $srv) {
$workflow:collectionWithItems += InlineScript {
$req = Test-Connection -ComputerName $using:pc.Name -Count 1 -BufferSize 1 -ErrorAction SilentlyContinue
if ($req) {
$using:pc | Add-Member -MemberType NoteProperty -Name "Online" -Value "Yes"
} else {
$using:pc | Add-Member -MemberType NoteProperty -Name "Online" -Value "No"
}
$using:pc
}
}
return $collectionWithItems
}
OnlinePC -svc $PC