PowerShell – Log a rolling ping with A timestamp

Below you will find a quick PowerShell one-liner to perform a continuous/rolling ping and log the results to a text file with a timestamp.

ping -t|Foreach{"{0} - {1}" -f (Get-Date),$_} > c:\script\ping_log.txt

This will perform a rolling ping (ping -t) to the google DNS server and output the results to a text file “c:\script\ping_log.txt” prefixed with a date-time stamp using Get-Date

Change the destination as required or if you are just testing for Internet access leaving as is fine.

You can also change the log file location “c:\script\ping_log.txt” as required.

The result will look as you can see in the above image.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.