Last active
June 27, 2020 05:34
-
-
Save jmurphyau/4dd4226cb3f5cf60eb5b7c3a9190b023 to your computer and use it in GitHub Desktop.
One line powershell to output network info and ping test multiple IPs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
powershell.exe -noprofile -command "& { function dt(){get-date -uformat '%Y-%m-%d-%H%M%S'};$c=$args[0];$ips=$args[1..$args.length];$j=@();$nl=[Environment]::NewLine;$d=('{0}\Desktop\network-info-{1}' -f ($Env:USERPROFILE,(dt))); function iscmd($cmd){[bool](get-command $cmd -erroraction silentlycontinue)} function ping() { start-job -ScriptBlock { ping.exe $args[0] -n $args[1] | foreach-object {('{0}: {1}' -f (get-date -uformat '%Y-%m-%d-%H%M%S'), $_)} >$args[2]} -argumentlist $args } ((test-path $d) -or (md $d)) >$null;write-host ('{0}{1}: Network info will be written to {2}' -f ($nl,(dt),$d));netsh dump >$d\netsh-dump.txt;netsh interface ipv4 show subinterfaces >$d\netsh-interface-ipv4-show-subinterfaces.txt;netsh wlan show interfaces >$d\netsh-wlan-show-interfaces.txt;ipconfig -all >$d\ipconfig-all.txt; foreach ($i in $ips) {$j+=(ping $i $c ('{0}\ping-{1}.txt' -f ($d,$i)))} if (iscmd 'get-netipaddress') { get-netipaddress | format-table >$d\get-netipaddress.txt; if (iscmd 'get-netneighbor') { get-netneighbor | format-table >$d\get-netneighbor.txt; get-netipaddress -addressfamily ipv4 | where {$_.ipaddress -ne '127.0.0.1'} | select -expandproperty ipaddress | foreach {$ip=($_ -replace '^(\d+\.\d+\.\d+)\.\d+$','$1'); (1..254|%{('{0}.{1}' -f $ip,$_)})} | foreach { start-process -windowstyle hidden ping.exe -argumentlist ('-n 1 -l 0 -f -i 2 -w 1 -4 {0}' -f $_) };sleep 3;$nc=(get-netneighbor -addressfamily ipv4 -state incomplete,probe,delay,stale,reachable,permanent 2>$null | select @{n='IPAddress';e={$_.IPAddress}},@{n='LinkLayerAddress';e={$_.LinkLayerAddress}},@{n='State';e={$_.State}},@{n='ComputerNames';e={(nslookup $_.IPAddress 2>$null | select-string -pattern '^Name:\s+(.*)$' | foreach { $_.Matches.Groups[1].Value })}}); $nc | format-table >$d\network-computers.txt; } } if (iscmd 'get-netroute') {get-netroute | format-table >$d\get-netroute.txt; $nexthops=(get-netroute -addressfamily ipv4 | where {$_.nexthop -ne '0.0.0.0'} | select -expandproperty nexthop); $nexthops >$d\nexthops.txt; foreach ($n in $nexthops) {$j+=(ping $n $c ('{0}\ping-nexthop-{1}.txt' -f ($d,$n)))}} wait-job $j >$null; write-output ('{0}{1}: Done' -f ($nl,(dt))); }" 10 1.1.1.1 8.8.8.8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment