Monthly Archive



Continuing our ramble through the goodies in PowerShell Community Extensions 2.0 we come to Tail-File. It is fairly easy to get the first n lines of a file.

Get-Content -Path C:\Scripts\HelpFiles\About\ -TotalCount 15

will display the first 15 lines in the file. This is comparable to the top command.  Getting the last 15 lines is a bit more difficult using get-content  - we have to read the file into an array and then display the last 15 records.

Alternatively, Tail-File comes galloping over the hill to our rescue

Tail-File -Path C:\Scripts\HelpFiles\About\ -count 15

will display the last 15 lines.  If we don’t use the –count parameter we get the last 10 lines.

We can even wait and pick off the latest lines of a growing log file if required.

Another useful cmdlet.

Technorati Tags: PowerShell,PSCX

Leave a Reply