Ping List Of Computers In PowerShell

PowerShell provides different commands and methods in order to ping a list of computers. We can check the connectivity to multiple computers in a simple and easy way with minimal effort by using the Net-Connection command or PowerShell script or foreach Loop.

Ping List of Computers with Net-Connection Command

The most practical and reliable way is using the Net-Connection command in order to check remote computer connectivity. the -TargetName option should be specified in order to provide multiple computers or remote systems.

PS> Test-Connection -TargetName,,

Alternatively, we can specify the IP addresses of the remote systems to ping.

PS> Test-Connection -TargetName,,

Ping List of Computers with PowerShell Script

We can use PowerShell scripts in order to ping a list of computers. Every computer or remote system is specified in a single line with the ping command and when the PowerShell script is executed these commands are called one by one.

PS> ./ping_multiple_computers.ps1

Ping List of Computers with foreach Loop

PowerShell foreach loop can be used to ping a list of computers. The computers can be specified in PowerShell or can be read from a text file. The computer names of IP addresses should be provided line by line in this text file.

The file is named Computers.txt and its content is like below.
$computer_list = Get-Content -Path "Computers.txt"

 foreach ($computer in $computer_list)
    $ip = $computer.Split(" - ")[0]
    if (Test-Connection  $ip -Count 1 -ErrorAction SilentlyContinue){
       Write-Host "$ip is up"
       Write-Host "$ip is down"

Leave a Comment