logmon -How to monitor only first/last x lines.

Document ID : KB000044449
Last Modified Date : 14/02/2018
Show Technical Document Details


If using command mode with Windows PowerShell, only first/last x lines can be monitored by logmon probe.


Unlike UNIX/Linux, Windows does not have head/tail commands. However, PowerShell has the equivalent "Get-Content" cmdlet. User can use the cmdlet for printing first/last x lines on Windows.


Windows PowerShell 2.0 or above


Here is the example procedure.

1. Create a batch file like below.


rem Wrapping powershell script in batch file 

@powershell -NoProfile -ExecutionPolicy Unrestricted "$s=[scriptblock]::create((gc \"%~f0\"|?{$_.readcount -gt 1})-join\"\");&$s" %*&goto:eof 

rem Printing first x lines on monitored log file

(Get-Content <Monitored log file name>)[0..x]


2. Open logmon probe configuration

3. Create a profile with command mode, and select the created batch file on [Command] field.

4. Apply the setting, then logmon probe will start to monitor.

Additional Information:

Windows PowerShell Management Cmdlets - Get-Content

Make it easier to wrap powershell scripts in batch files