PowerShell Tail – Watch log file as data is appended by script

Add this snippet to any script which writes to a log file, and it will open a second PowerShell console window with which you can watch the logfile as it is updated in real-time.

1
2
$Logfile = "$env:systemroot\Temp\$Logname.log"
Start-Process -FilePath $pshome\powershell.exe -ArgumentList @("-NoExit","&`{Get-Content -LiteralPath $Logfile -Tail 50 -Wait`}")

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.