Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I recently finished a script to ping every computer/workstation on a list and output it in a nice format.

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...