How to Ping a list of Computer in PowerShell

Liem Nguyen 11 Reputation points

Hi everybody!
I have a list of Computers with IP

ListOfComputerIP.txt like this: - John'PC - Tim'PC - 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

    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"
            Write-Host "$ip is down"

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

    Andreas Baumgarten

    8 people found this answer helpful.

  2. SUNOJ KUMAR YELURU 13,971 Reputation points MVP

    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

    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

    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?