I'm trying to create a script that checks if a specific network adapter can access the internet. Currently, I'm using `(Get-NetConnectionProfile -InterfaceAlias "Ethernet").IPv4Connectivity`, but I want a more concrete test. I'd like to ping or perform another reliable test, like DNS resolution, from a specific source IP or network interface, but I'm having a hard time finding a solution.
I've looked into `Test-Connection`, but it doesn't allow me to specify the source address or interface for local tests; it seems to only work for remote machines, which can lead to misleading results.
When trying `Test-NetConnection`, using `-ConstraintInterface` or `-ConstrainSourceAddress` needs `-DiagnoseRouting`, and it doesn't seem to provide a real connection test in the output, making it unhelpful for my case.
I even considered using `[System.Net.NetworkingInformation.Ping]`, but that also lacks functionality for constraining by source address or interface. After digging around, I found a GitHub issue discussing this, but no clear solutions came up.
While I did attempt to use ping.exe, I ran into issues with various OS versions showing differing output formats, which complicates parsing for a "ping wrapper" in PowerShell.
Ultimately, I want to ensure that if the connection is healthy on adapter A, I can disable adapter B, and vice versa. Windows seems to make this overly complicated even with metrics set on the interfaces.
5 Answers
You could use `ping.exe` with the `-S` option to specify the source address, like this: `ping -S 10.200.1.20 8.8.8.8`. But it seems like you're already using a wrapper, so that makes sense. Also, check out `Win32_PingStatus` via `get-ciminstance`—might be useful too! You might also want to run a traceroute instead of or alongside a ping to get more details about the connection.
This is a classic case of Windows networking confusion. Typically, you can't just constrain ping to an adapter because of how routing works. Each adapter has its own IP and gateway, and the routing metric determines which one takes priority. If you want both adapters to have distinct networks, you'd have to assign them separate networks and possibly set a static route for one. But honestly, a firewall or WAN load balancer might simplify this process for you!
Are you using these interfaces for redundancy or multiple networks? If it's for redundancy, could adjusting the interface metric help? If it's dual NICs, you might want to look into using `Set-NetRoute`. That could make a difference!
It's actually for a dual-network setup—one for LAN and another for LTE. It helps me access the network and troubleshoot if the firewall goes down.
If you have multiple NICs, using `Test-Connection -Source ` should do the trick. This way, you can specify which adapter’s IP you want to use for the test. Give that a shot!
Honestly, the whole idea of testing through multiple adapters can be tricky because usually, only one adapter at a time is used for internet access, namely the one with the default route. If you set up your default route correctly, Windows will know which one to use. You might want to reconsider how you want to test connectivity.

I get what you're saying, but we need a backup plan for when our firewall fails, like during firmware updates. Some of our locations are far away from IT support.