How to monitor only first/last x lines - PowerShell
search cancel

How to monitor only first/last x lines - PowerShell


Article ID: 44449


Updated On:


DX Unified Infrastructure Management (Nimsoft / UIM)


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.



Any UIM and logmon version



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]


  1. Open logmon probe configuration
  2. Create a profile with command mode, and select the created batch file on [Command] field.
  3. Apply the setting, then logmon probe will start to monitor.



Additional Information

Additional Information:

Windows PowerShell Management Cmdlets - Get-Content

Make it easier to wrap powershell scripts in batch files