How to tail logs with Windows PowerShell

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.

Log File Notepad
Log File Notepad

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
Image 6
Get the last 10 lines in a text file with PowerShell

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
Get Content Wait 1
Get Content Wait 1

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
Get Content Wait Ogv 1
Get Content -Wait | OGV

Out-GridView allows you to filter for specific events. So it will be updated live and you can filter the data. Awesome!

Try one of our IT labs

Want to try one of our online IT labs? Enter your email below and we will send you an Active Directory IT lab!

Table of Contents
    Add a header to begin generating the table of contents
    Blogpostctadesktop

    Free trial to boost your IT skills

    Practice on REAL servers, learn from our video lessons, interact with the Server Academy community!