In a recent customer conversation, they were excited that PowerShell 5.0 would contain the option to tail a log file. While they were excited to get that feature, they were less excited to hear that PowerShell 3.0 had already added the –Tail parameter to the Get-Content cmdlet. Previously there have been other solutions to get this functionality, but is now native in PowerShell.
As an example:
Gets the last two lines of the log file:
Get-Content .u_ex160511.log -Tail 2
Gets the last two lines of the log file, and waits for more.
Get-Content .u_ex160511.log -Tail 2 –Wait
Let's look at a quick example of the latter command. In the below example, we are seeing the last two lines in an IIS log. Since the –Wait parameter was added Get-Content will wait for new lines to be written to the file.
Shorty after, there is a connection to a health mailbox. Note that the new lines were simply added to the screen and we did not have to re-issue the PowerShell command.
For the Exchange admins out there, please ensure that the versions of .NET Framework and PowerShell installed on the Exchange servers are listed in the support matrix.