Guide

Ping to a log file with timestamps

To log a continuous ping with timestamps on Windows, pipe ping -t through PowerShell. Every reply and timeout is stamped with the date and time.

Applies to Windows 10 and 11 · Windows PowerShell 5.1 or PowerShell 7
Read 1 min
Quick answer

Pipe ping -t through PowerShell to stamp each reply with the date and time, show it, and append it to a log file.

The steps and the reason are below.

A device that drops off the network for a minute every few hours is hard to catch while you watch. Leave this running instead, then read the log afterwards: every reply and every timeout has the date and time next to it.

Start a ping log with timestamps

The command below pings one address until you stop it, and writes every line to ping.log with the date and time in front.

Open PowerShell in the folder where the log should go (in File Explorer, type powershell in the address bar and press Enter). Paste this, with your device’s address in place of 192.168.1.31:

ping.exe -t 192.168.1.31 | Where-Object { $_ } | ForEach-Object {
    $line = '{0:yyyy-MM-dd HH:mm:ss}  {1}' -f (Get-Date), $_
    $line
    Add-Content -Path ping.log -Value $line
}
  • Each reply shows on screen and is added to ping.log in that folder.
  • Running it again adds to the same log; it never overwrites.
  • Press Ctrl+C to stop.

-t keeps pinging until you stop it. Microsoft’s ping reference lists the other options, such as -n for a fixed count.

The log looks like this:

2026-10-27 22:19:38  Pinging 192.168.1.31 with 32 bytes of data:
2026-10-27 22:19:38  Reply from 192.168.1.31: bytes=32 time=1ms TTL=64
2026-10-27 22:19:39  Reply from 192.168.1.31: bytes=32 time=1ms TTL=64
2026-10-27 22:19:44  Request timed out.

List only the dropped pings

Select-String pulls every failed ping out of the log, with the time it happened:

Select-String -Path ping.log -Pattern 'timed out|unreachable|failure'

Make a batch file you can double-click

A batch file runs the same logger without opening PowerShell first.

Save this as ping-log.bat. It asks for the address, then logs to ping-<address>.log next to the file:

@echo off
set /p ip=Address to ping: 
powershell -NoProfile -Command "ping.exe -t %ip% | Where-Object { $_ } | ForEach-Object { $line = '{0:yyyy-MM-dd HH:mm:ss}  {1}' -f (Get-Date), $_; $line; Add-Content -Path 'ping-%ip%.log' -Value $line }"

Some company policies block downloaded .bat files. Making it yourself in Notepad and saving it with the .bat extension works the same.