On Linux I’d type tail -f to watch a log. PowerShell has the same trick built into Get-Content, and it is easy to forget because the parameters have different names.
Show the last 20 lines and keep waiting for new ones:
Get-Content -Path C:\Logs\app.log -Tail 20 -Wait
-Tail (alias -Last) picks the number of lines from the end. -Wait keeps the file open and checks it once per second, printing new lines as they arrive. Press Ctrl+C to stop. You can combine it with a filter to follow only the interesting lines:
Get-Content C:\Logs\app.log -Tail 50 -Wait | Select-String "error"
Caveats:
-Waitcannot be combined with-Raw.- If the file is deleted while you wait, the command stops with a non-terminating error. That is relevant for logs that rotate by renaming or deleting the file, so you may need to start it again after a rotation.
- It checks once per second, so output is slightly delayed compared to a real tail on Linux.
- Do not use
-Tailwith a negative value, which is an error, and-Tail 0returns no lines. - The encoding follows the PowerShell version: PowerShell 7 reads UTF-8 without a byte order mark by default, so a log in another encoding may show odd characters. Add
-Encodingif needed.
The docs also say that getting only the last lines with -Tail is faster than reading a whole file into a variable and indexing it.
Further reading: Microsoft Learn: Get-Content