Powershell · 2016-03-18

PowerShell – Fast Ping

Source: https://gist.github.com/mbrownnycnyc/9913361

This is a very fast way to ping a server using PowerShell.

# with reference to http://theadminguy.com/2009/04/30/portscan-with-powershell/ 
2 function fastping{ 
3   [CmdletBinding()] 
4   param( 
5   [String]$computername = "127.0.0.1", 
6   [int]$delay = 100 
7   ) 
8 
 
9   $ping = new-object System.Net.NetworkInformation.Ping 
10   # see http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ipstatus%28v=vs.110%29.aspx 
11   try { 
12     if ($ping.send($computername,$delay).status -ne "Success") { 
13       return $false; 
14     } 
15     else { 
16       return $true; 
17     } 
18   } catch { 
19     return $false; 
20   } 
21 }