How to Multithread PowerShell Ping Script

前端 未结 3 617
逝去的感伤
逝去的感伤 2020-12-11 20:50

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

3条回答
  •  失恋的感觉
    2020-12-11 21:20

    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
    

提交回复
热议问题