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 windowstect.com, linuxtect.com,wisetut.com
Alternatively, we can specify the IP addresses of the remote systems to ping.
PS> Test-Connection -TargetName 192.168.1.10,10.10.1.1,8.8.8.8
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.
ping windowstect.com
ping linuxtect.com
ping wisetut.com
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.
192.168.1.1 windowstect.com 8.8.8.8
$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"
}
else{
Write-Host "$ip is down"
}
}