You want to ping multiple computers at once? Can’t? Yes you can, with PowerShell. In this post I’ll show you a few examples of how you can ping multiple computers. We will use the Test-Connection cmdlet for this task. It’s going to be exciting. Let’s get started.
Open PowerShell 5.1 or PowerShell 7.
Example 1: Ping multiple Computers
Test-Connection -ComputerName sid-500.com,192.168.0.1,microsoft.com -Count 1
Example 2: Ping all Domain-Computers
Test-Connection -ComputerName (Get-ADComputer -Filter * | Select-Object -ExpandProperty Name) -Count 1
Example 3: Ping Computers from Text File
Test-Connection -ComputerName (Get-Content C:\Data\Computers.txt) -Count 1
Example 4: Subnet Ping
Note that this will only work in PowerShell 7 because of the -Parallel Parameter.
# PowerShell 7
$subnet = '192.168.0.'
$ips = 1..254
$ips | ForEach-Object -Parallel {
Test-Connection -ComputerName $using:subnet$_ -Count 1
}
Categories: PowerShell
Hi Patrick,
I use a lot of your powershell script, thanks fot that! I usually re-write them to my needs.
This time i think i can actually say your doing it wrong :-p.
I don’t use Test-NetConnection anymore for ping/port actions.
I use:
$Socket = New-Object System.Net.Sockets.TcpClient
The function is 127 lines, it “pings” and does port checks for multiple machines.
WHY?
Because its significantly faster. (Did not test it in powershell 7 but i dont think its faster)
I know its not actually powershell 🙂
LikeLike
Test-NetConnection was developed by Microsoft to do port Scans. I cant see something wrong, there are always different ways for achieving goals.
LikeLike