Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I use Powershell to timestamp pings with 24-hour time?

I need to ping things in Windows and know what time pings were received or missed; the timestamps should reflect 24-hour time (instead of an AM/PM suffix).

How can I do this in Powershell?

like image 756
Mike Pennington Avatar asked Mar 03 '23 22:03

Mike Pennington


1 Answers

You can timestamp pings wth a foreach() loop; Get-Date can take a format string:

C:\> powershell
PS C:\> ping.exe -t 4.2.2.2 | Foreach{"{0} - {1}" -f (Get-Date -f "yyyyMMdd HH:mm:ss"),$_}
20190601 14:33:03 -
20190601 14:33:03 - Pinging 4.2.2.2 with 32 bytes of data:
20190601 14:33:03 - Reply from 4.2.2.2: bytes=32 time=70ms TTL=123
20190601 14:33:04 - Reply from 4.2.2.2: bytes=32 time=71ms TTL=123
20190601 14:33:05 - Reply from 4.2.2.2: bytes=32 time=70ms TTL=123
like image 58
Mike Pennington Avatar answered Apr 08 '23 13:04

Mike Pennington