Follow a growing log with PowerShell Get-Content -Tail -Wait

  • Published: 2026.11.23
  • Updated: 2026.11.23
  • Windows

When a log is still being written, reopening it after every action makes troubleshooting slow. PowerShell can show its latest lines and keep the command running as new lines arrive.

These examples use a UTF-8 text file on Windows and work in Windows PowerShell 5.1 and PowerShell 7. Replace .\app[1].log with your log’s path. -LiteralPath treats the square brackets as part of the filename.


Read the last lines once

Get-Content -LiteralPath '.\app[1].log' -Encoding UTF8 -Tail 20

This returns up to 20 lines from the end, then finishes. A file with fewer than 20 lines returns the lines it contains.

Keep watching for new lines

Get-Content -LiteralPath '.\app[1].log' -Encoding UTF8 -Tail 20 -Wait

The command first shows the existing tail and then waits for appended lines. Microsoft documents a check once per second, so updates need not appear immediately. Press Ctrl+C in that terminal to stop watching.

In a small sample, a file initially contained alpha and beta. Watching with -Tail 1 -Wait first produced beta; appending a complete gamma line produced gamma next.

Show only lines added after watching starts

Get-Content -LiteralPath '.\app[1].log' -Encoding UTF8 -Tail 0 -Wait

This starts without printing existing lines. In the same sample it showed only the appended gamma line.

Check errors and log replacement

The path must point to an existing readable file. A missing file produces an error rather than a watcher waiting for that filename to appear. Match -Encoding to the actual log; the explicit UTF-8 setting here is for UTF-8 logs.

Microsoft notes that deleting the watched file interrupts waiting with an error. If an application rotates, renames or replaces logs, check the current file and restart the command as needed. The append examples do not demonstrate automatic following across rotation.

-Wait cannot be combined with -Raw. For whole-file strings and line arrays, see Get-Content -Raw and individual lines.

References

このブラウザからの自分のアクセスを解析から除外できます。