1
(1..254) | % { 
    $ping = New-Object System.Net.Networkinformation.Ping
    [Void](Register-ObjectEvent $ping PingCompleted -Action {
        param($s, $e);
        if($e.Reply.Status -ne "TimedOut") {
            Write-Host $e.Reply.Address, ($e.Reply.RoundtripTime.toString() + "ms")
        }
    })
    [void]$ping.SendPingAsync(“192.168.1.$_”)
}

I tested this on a small subnet. It finds 1-4 out of six active windows boxes while nmap and a lot of simple scanner apps find all six. If I use synchronus Ping.Send() it finds all of them. I tried everything and am looking for help as it seems to be a PS thing and I'm a PS noob..

user1276423
  • 109
  • 6
  • Why are you changing your exec policy? Either it's a script, so it's already allowed, or not, so it's unneeded. I think Write-Host is used concurrently. Did u try to open up a dialog or so on? – Clijsters Mar 25 '17 at 23:46
  • ...oh and did you tested whether `Test-Connection "192.168.1.$_" -AsJob` shows the same behaviour? – Clijsters Mar 26 '17 at 00:09
  • I ended up using this instead. It's slower but works.. `$start = 1 $end = 255 while ($start -le $end) { $IP = "192.168.1.$start" $result = Test-Connection -ComputerName $IP -count 1 -Quiet if($result -eq 'True'){ Write-Host $IP } $start++ }` – user1276423 Mar 26 '17 at 10:30

0 Answers0