Tailing Log Files

by Apr 22, 2016

You can ask PowerShell to monitor a text-based log file and output any changes. It is a one-liner:

Get-Content c:\Windows\WindowsUpdate.log -Wait -Tail 0

Typically, Get-Content would only read the text content from the given file. -Wait instructs PowerShell to keep waiting for more information, so PowerShell stops and monitors the file for subsequent changes.

-Tail tells the cmdlet how many of the existing content you want to read. If you just want to monitor for new content, set it to 0.

Note that there are situations when the file cache will prevent real time notifications. So if you change the file, and PowerShell won't report these changes immediately, then this may be due to some caching. One workaround is to "trigger" the cache in intervals by calling Get-Item with the path to the monitored file. This of course would have to be done in a separate thread.

Twitter This Tip! ReTweet this Tip!