I have made a GUI ping tool for mass pinging of a range of IP-addresses.
I have tried the tool with a test-connection -asjob function - it works, but it seems to have a problem with big ranges (more than 5000 addresses).
I am now interested in trying SendPingAsync. The function works great by itself in ISE and obviously normal PS, but when I run it in the GUI through Powershell Studio or ISE, it gets stuck.
I have run the debug and the threading tasks is input into the variable as a bunch of System.Threading.Tasks.Task`1[System.Net.NetworkInformation.PingReply].
So far, so good... but then it gets stuck and the result is never pulled out. It seems the threading task never finishes.
Is it a limitation with winforms ? or maybe just lack of knowledge on my part?
Here is the fuction and after that how you can run it:
Code: Select all
function Ping-Fast
{
param ($servers)
$i = 0
$results = New-Object 'System.Collections.Generic.List[System.Object]'
$PingAsync = foreach ($server in $servers)
{
(New-Object Net.NetworkInformation.Ping).SendPingAsync($server,250)
}
[System.Threading.Tasks.Task]::WaitAll($PingAsync)
foreach ($result in $PingAsync.result)
{
if ($result.Address-like "0.0.0.0")
{
$address = $servers[$i]
$Reachable = "NO"
}
else
{
$address = $result.address
$Reachable = "YES"
}
$obj = New-Object -TypeName PSObject
$obj | Add-Member -MemberType NoteProperty -Name "Nr" -Value $i
$obj | Add-Member -MemberType NoteProperty -Name "Address" -Value $address
$obj | Add-Member -MemberType NoteProperty -Name "Reachable" -Value $reachable
$results.add($obj)
$i++
}
return $results
}
Code: Select all
$ipsLastOctet = @(1..254)
$ips = New-Object 'System.Collections.Generic.List[System.Object]'
foreach ( $ipLastOctet in $ipsLastOctet )
{
$ips.add("192.168.0.$ipLastOctet")
}
Ping-Fast -servers $ips
- Test-connection -asjob:
CPU: Mostly used around 25%-35% but went to 100% usage at times.
RAM: It stopped processing when ISE was at 2088 MB usage. Didn't rise or fall after that.
- SendPingAsync:
Did a test without the timeout value of 250 and it finished at 1 minute and 49 seconds.
CPU: Mostly at 10%-13% but peaked at 17%.
RAM: Mostly at around 180-200 MB usage but peaked at around 250 MB usage.
That is a huge difference and why I am so very interested in switching the functions.
Edit Edit: I have attached a small test form with the function implemented. It will just post the output with out-gridview but it demonstrates the problem.
It uses BarryCWT's excellent get-iprange function to get the range of IP-addresses to send to the ping function ( https://gallery.technet.microsoft.com/s ... a-60c5bb6b ).
Currently is is set for a /30 network (for ease of debugging) but you can set the range yourself in the $buttonPing_Click event scriptblock.