如何使用多线程PowerShell Ping脚本 [英] How to Multithread PowerShell Ping Script
本文介绍了如何使用多线程PowerShell Ping脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我最近完成了一个脚本,可以对列表中的每台计算机/工作站执行ping操作,并以一种不错的格式输出它.
I recently finished a script to ping every computer/workstation on a list and output it in a nice format.
要在下一个列表上ping数以千计的计算机,因此可能需要一段时间才能正常运行.我如何能够对此进行多线程处理,以便可以在合理的时间内完成工作?
There are thousands of computers to ping on the next list so it would take a while to run normally. How might I be able to multithread this so the job can be completed within a reasonable time-frame?
推荐答案
workflow Ping
{
param($computers)
foreach -parallel ($computer in $computers)
{
$status = Test-Connection -ComputerName $computer -Count 1 -Quiet
if (!$status)
{ Write-Output "Could not ping $computer" }
}
}
$computers = @(
"wd1600023",
"sleipnir"
)
Ping $computers
这篇关于如何使用多线程PowerShell Ping脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文