Powershell script to parse log file for error text

Topics: User Forum
Aug 13, 2012 at 2:39 PM
Edited Aug 13, 2012 at 2:46 PM

Here's a sample Powershell script I wrote for Polymon to parse a log file for a Windows Oracle server and alert if it finds certain error entries.  Of course it can be modified to check any file for any kind of text.

Create a new blank Powershell monitor, and paste the code below.  Set your desired target logfile, and set the text entries that you'd like to alert on.

No guarantees that it's the most elegant code ever written, but it's at least minimally effective for my purposes...


$Status.StatusID = 1
$Status.StatusText = "OK."
#open up the logfile using the e$ adminstrative share
$file = Get-Content 

switch -wildcard ($file)

        "*corrupt*" {$Status.StatusID=3;$Status.StatusText = $Entry.name,"Found keyword 'Corrupt'"; break} 
        {(($_ -like "*ora-*") -and ($_ -notlike "*ora-02097*") -and ($_ -notlike "*ora-00439*"))} 
         {$Status.StatusID=3;$Status.StatusText = $Entry.name,"Found keyword 'Ora-'"; break} 
        default {}