How to tail logs with Windows PowerShell

Written by Paul Hill on October 15, 2020

Paul Hill is the founder of and IT instructor to over 500,000 students online!

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!

Get the "Intro to IT" ebook FREE!

The ebook covers IT basics and will help you get started with building your IT career.  Enter your email below and we'll send you this powerful ebook along with other useful IT tips!

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

    Sign up free and start learning today!

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