How to Ping a list of Computer in PowerShell

Liem Nguyen 11 Reputation points
2021-01-30T11:05:38.047+00:00

Hi everybody!
I have a list of Computers with IP

ListOfComputerIP.txt like this:

192.168.1.2 - John'PC
192.168.1.3 - Tim'PC
192.168.1.4 - Green'PC

Now I need a loop command to Ping all that Computer via IP to check every single computer Up or Down.

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,416 questions
{count} votes

4 answers

Sort by: Most helpful
  1. Andreas Baumgarten 98,626 Reputation points MVP
    2021-01-30T11:44:09.907+00:00

    Please try this:

    $computers = Get-Content -Path "ListOfComputerIP.txt"
    foreach ($computer in $computers)
        {
        $ip = $computer.Split(" - ")[0]
        if (Test-Connection  $ip -Count 1 -ErrorAction SilentlyContinue){
            Write-Host "$ip is up"
            }
        else{
            Write-Host "$ip is down"
            }
        }
    

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    8 people found this answer helpful.

  2. SUNOJ KUMAR YELURU 13,971 Reputation points MVP
    2021-01-30T11:41:02.803+00:00

    Hi @Liem Nguyen

    Yes, it is possible to ping list of computers using powershell script.

    If the Answer is helpful, please click Accept Answer and up-vote, this can be beneficial to other community members.

    0 comments No comments

  3. Ron LaJeunesse 1 Reputation point
    2022-11-02T13:39:20.087+00:00

    Is your text file in the solution a list of computers, or a list of computer names and IP Addresses, are there column headers, can this be done with just computer names?

    0 comments No comments

  4. Milofields 1 Reputation point
    2022-12-06T17:32:18.497+00:00

    This working for me, however it's truncating the hostname and only using the first 8 characters of the hostname. Is there a way to have it use more than 8 characters in the hostname?