O cmdlet Test-Connection
permite especificar o endereço de origem com o parâmetro -Source
. Podemos testar os endereços usados por cada adaptador.
$adapters = Get-NetIPAddress -AddressFamily ipv4 | Where-Object InterfaceAlias -in (Get-NetAdapter | Select-Object -ExpandProperty Name) | Select-Object IPAddress,InterfaceAlias
$adapters | % {
Test-Connection -Source $_.IPAddress -Destination 8.8.8.8 -ErrorAction SilentlyContinue | Out-Null
if($?) {
write-host $_.InterfaceAlias "(" $_.IPAddress ") can connect to the internet."
}
else {
write-host $_.InterfaceAlias "(" $_.IPAddress ") failed to connect to the internet."
}
}
Saída:
Local Area Connection ( 10.1.1.2 ) can connect to the internet
Ethernet 2 ( 10.1.1.3 ) failed to connect to the internet.
Wireless Network Connection ( 10.1.1.4 ) failed to connect to the internet.