How to Ping a list of Computer in PowerShell

Liem Nguyen 91 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 for business Windows Server User experience PowerShell
{count} votes

4 answers

Sort by: Most helpful
  1. Andreas Baumgarten 123.4K Reputation points MVP Volunteer Moderator
    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

    11 people found this answer helpful.

  2. SUNOJ KUMAR YELURU 15,256 Reputation points MVP Volunteer Moderator
    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.


  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 6 Reputation points
    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?


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.