cmdlets - Determining internet connection using Powershell -
is there simple cmdlet can run in powershell determine if windows machine connected internet through ethernet or through wireless adapter? know can determine on gui, want know how can managed in powershell.
the powershell cmdlet get-netadapter
can give variety of info network adapters, including connection status.
get-netadapter | select name,status, linkspeed name status linkspeed ---- ------ --------- vethernet (meandmahvms) 10 gbps vethernet (theopenrange) disconnected 100 mbps ethernet disconnected 0 bps wi-fi 2 217 mbps
another option run get-netadapterstatistics
show stats connected device, use way of knowing connected web.
get-netadapterstatistics name receivedbytes receivedunicastpackets sentbytes sentunicastpackets ---- ------------- ---------------------- --------- ------------------ wi-fi 2 272866809 323449 88614123 178277
better answer
did more research , found if adapter has route 0.0.0.0, it's on web. lead pipeline, return devices connected web.
get-netroute | ? destinationprefix -eq '0.0.0.0/0' | get-netipinterface | connectionstate -eq 'connected' ifindex interfacealias addressfamily nlmtu(bytes) interfacemetric dhcp connectionstate policystore ------- -------------- ------------- ------------ --------------- ---- --------------- ----------- 17 wi-fi 2 ipv4 1500 20 enabled connected activestore
Comments
Post a Comment