Powershell ping indefinitely

3

In Powershell is there a better way to ping a host indefinitely besides doing something like this:

$max = [System.Int32]::MaxValue
ping host -count $max


The '%WINDIR%\System32\ping.exe' has a '-t' option to ping until Ctrl-C is pressed.

Luke Quinane

Posted 2009-07-24T04:03:06.340

Reputation: 397

Answers

4

while (1) {
   ping host
}

This will ping indefinitely until you press Ctrl-C just like ping -t would.

John T

Posted 2009-07-24T04:03:06.340

Reputation: 149 037

1while (1) { ping host -count 1000 } has the nice side effect of hiding most of the ping statistics. – Luke Quinane – 2009-07-24T06:56:50.253

6

There is nothing at all wrong with John T's answer, but I will point out just for completeness sake that ping.exe is still there so this would work just fine in PS as well:

ping.exe host -t

EBGreen

Posted 2009-07-24T04:03:06.340

Reputation: 7 834

2

in windows powershell you can use Test-Connection cmdlet.

This cmdlet sends ICMP echo request packets ("pings") to one or more computers using WMI

although it does not have any -t option but it have -count option that u can indicate number of ICMP pocket to send
instead you can use this cmdlet this way:

while (1) {
   Test-Connection host
}  

and result is like bellow:
Test-Connection Powershell Command result

AminM

Posted 2009-07-24T04:03:06.340

Reputation: 502