I needed to monitor the uptime of a network device, but with the added twist of tracking when dropped packets occurred. While ping
doesn’t natively support a timestamp option, Powershell lets me quickly craft a command to do so:
ping -t 8.8.8.8|Foreach{"{0} - {1}" -f (Get-Date),$_}
PS C:\Users\Greg> ping -t 8.8.8.8|Foreach{"{0} - {1}" -f (Get-Date),$_}
2025-05-20 11:29:25 AM -
2025-05-20 11:29:25 AM - Pinging 8.8.8.8 with 32 bytes of data:
2025-05-20 11:29:25 AM - Reply from 8.8.8.8: bytes=32 time=19ms TTL=114
2025-05-20 11:29:26 AM - Reply from 8.8.8.8: bytes=32 time=16ms TTL=114
2025-05-20 11:29:27 AM - Reply from 8.8.8.8: bytes=32 time=17ms TTL=114
2025-05-20 11:29:28 AM - Reply from 8.8.8.8: bytes=32 time=18ms TTL=114
2025-05-20 11:29:28 AM -
PS C:\Users\Greg>
The crummy part is that when I trigger an endless ping (-t option), cancelling it via. CRTL-C doesn’t display the statistics (total ping sent, total dropped, RTT summary, etc).
If I want to log it to a file:
ping -t 8.8.8.8|Foreach{"{0} - {1}" -f (Get-Date),$_} > desktop\ping_log.txt