How can I ping an IP range and avoid “Destination host unreachable” messages?

0
8
Asked By TechnoWiz42 On

I'm trying to ping a range of IP addresses (10.1.1.1 to 10.1.1.254) and I want to get results that show the IP is reachable without including any 'Destination host unreachable' responses. For instance, I want to see something like 'Reply from 10.1.1.55: bytes=32 time=3ms TTL=53' but exclude any messages that say 'Destination host unreachable.' How can I modify my PowerShell script to filter out these unwanted results? Here's what I have so far:

```
$iprange = 1..254
Foreach ($ip in $iprange)
{
$computer = "10.1.1.$ip"
$status = Test-Connection $computer -count 1 -Quiet
if (!$status)
{
$computer + " - available"
}
}
```

2 Answers

Answered By PingingPro88 On

You might want to try using `Test-NetConnection -Quiet` instead. This command allows you to suppress warnings and handle errors without outputting the 'Destination host unreachable' messages. Check out the documentation [here](https://learn.microsoft.com/en-us/powershell/module/nettcpip/test-netconnection?view=windowsserver2025-ps) for more details.

Answered By SkepticalSam On

Just a heads up, some of these commands might not support the `-Quiet` parameter as you think. You can use `Test-NetConnection -WarningAction SilentlyContinue -ErrorAction SilentlyContinue` and then check the `PingSucceeded` attribute. That way, you can keep your output clean and to the point!

HelpfulHank -

Actually, `Test-Connection` does support `-Quiet`. It's listed under `-InformationLevel Quiet`, but that's just a shorthand people often use.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.