The PowerShell equivalent of Unix Tail

I’ve always been a little jealous of the *NIX admins because of their ability to use TAIL to watch log files. You could always download third-party apps that generally achieved the same thing in the Windows world, but that requires that you distribute that app to every server that you want to be able to use the command on. It has always bothered me that it wasn’t built into the system since not every application writes entries to the windows event logs.

Well, those days are over thanks to PowerShell. As it turns out, the get-content cmdlet supports a parameter called -wait that achieves the same thing as tail. The actual syntax is as follows:

get-content c:\filename.txt -wait

It’s pretty straightforward.  To see it in action, create a file called tail.txt in c: and then open it in your text editor of choice (I prefer notepad++).  Leaving the text editor open, switch to PowerShell and type:

get-content c:\tail.txt -wait

You will notice that PowerShell performs a carriage return and…. waits.  Go figure.  Make sure you set the text editor and PowerShell up so that you can see both at the same time.  Return to your text editor and type anything you like, then hit save.  When you hit the save button you should see your changes posted to the PowerShell window.

This is of course excellent for managing applications that rely on logging to text files, and since it is on all windows 2008 servers, and can (should) be installed on all windows 2003 servers, it means that my reliance on third-party tail-like apps is over.  Awesome.

Everything is better with PowerShell.

Advertisements
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: