Monitoring Log Files

by Nov 15, 2013

Beginning in PowerShell 3.0, it is easy to monitor text-based log files in real-time. Try this:

$Path = "$home\Desktop\testfile.txt"

'Test' | Out-File "$home\Desktop\testfile.txt"
notepad $Path

Get-Content -Path $Path -Tail 0 -Wait | Out-GridView -Title $Path

This will create a test file on your desktop, and then open the file in the Notepad. PowerShell will then start monitoring the file. Once you type new text into the Notepad window and save it, the changes will appear in a PowerShell grid view.

Simply replace the path with any text-based log file you'd like to keep an eye on. Since PowerShell is blocked while it is monitoring the file, you may want to execute the code in a separate PowerShell instance.

Twitter This Tip! ReTweet this Tip!