It is often very useful to have the ability to watch a log file as it updates in real-time. Linux and Mac users are accustomed to having the ‘tail’ utility out-of-the-box, but Windows users have had to use additional utilities. Some Windows options that I’ve used include
- tail.exe (from the Windows 2003 Resource Kit, amazingly it still works on current operating systems)
- cmtrace.exe (from the SCCM management utilities)
- Notepad++ with the “Monitoring” option
Thanks to a tip from @atlauren given in another forum, I can add another option, which does not require installing or downloading anything. The following PowerShell command can monitor a log in real-time:
powershell -executionpolicy bypass "get-content -path 'c:\Program Files (x86)\BigFix Enterprise\BES Client\__BESData\__Global\Logs\20200609.log' -wait"
To expand on this, here is a one-liner to find the latest BES Client Log, display the last 50 lines from it, and continue to ‘tail’ the file as it is updated. This should be equivalent to ‘tail -50 -f’ :
powershell -executionpolicy bypass "get-childitem -path 'c:\Program Files (x86)\BigFix Enterprise\BES Client\__BESData\__Global\Logs' | sort LastWriteTime | select -last 1 | get-content -last 50 -wait"