Lately I’ve been needing to watch some logs that are creating by my IIS 10 server. The problem is that they are in TXT format and I can’t see live updates unless I close and open the file.
I work with Centos 7 (open source Linux OS) and they have a wonder tail command that you can use to get scrolling updates as a file is changed. It is perfect for log files!
Well…come to find out you can do the same thing with PowerShell:
Get the last 10 lines of a text file:
This is a simple command to just get the last 10 lines of text in a file:
Get-Content [path\to\textfile.txt] -tail 10
Follow a TXT file with PowerShell
This command is equivilent to tail -f on Centos Linux. It will output all of the file contents and update each time a new line is added:
Get-Content [path\to\textfile.txt] -wait
Follow TXT file with PowerShell OGV command
My personal favorite (and even better than the standard -tail command IMO) is piping the output to Out-GridView or OGV:
get-content [path\to\textfile.txt] -wait | ogv
Out-GridView allows you to filter for specific events. So it will be updated live and you can filter the data. Awesome!
Free trial to boost your IT skills
Practice on REAL servers, learn from our video lessons, interact with the Server Academy community!