PowerSehll 3.0 Parse Event Logs

Hi everyone,

I have been searching for a PowerShell script that searched the Description part of the event log in the system logs.  Therefore, if the description mentions 'fatal' but the event id were different, hence the need to search the description.

If anyone can assist very much grateful.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David Paris VicenteInfrastructure DesignerCommented:
Something like this?

$a = get-winevent -path [path to evt] -oldest nnn |
  where-object {$_.message -match "fatal"}
CaussyRAuthor Commented:
Rather than state the location of the evt file, I need this similar to the below, which at the moment is not working :

Get-WinEvent -computername RAJC -Logname Security -max 10 | Select ID,Level,Message | Where-Object { $_.Message | findstr /C:"stopped"}

I am trying to get to a script where I can enter the hostname and key word to find then PS will check the necessary event log but for starters just need to parse the event log...

Thanks for your reply.
Steven HarrisPresidentCommented:
What is the error received on your code?  Perhaps:

Get-WinEvent : Could not retrieve information about the Security log. Error: Attempted to perform an unauthorized

Now try this:

Get-WinEvent -computername RAJC -Logname Application -maxEvents 10 | 
Select ID,Level,Message | Where-Object { $_.Message | findstr /C:"stopped"}

Open in new window

What error do you get (if any)?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Don't use findstr here, that involves a lot of overhead.
For local events, filtering at client side is ok, or if you only parse a few records:
Get-WinEvent -LogName System | ? { $_.Message -like '*stopped*' } | select ID, Level, Message

Open in new window

For remote logs you should try to create a filter XML via the EventLog viewer, and use that filter string in Get-WinEvent -FilterXML, to allow for filtering on the remote machine.
CaussyRAuthor Commented:
I tried the above but get-winevent didn't bring back any message data.  Get-eventlog does bring back the message data.  I would prefer to use get-winevent as this works a lot faster.
Wasim ShaikhCommented:
If I understood the question, you are trying to find events which contains spcific word i.e., fatal.
and it doesn't matters which event ID it is.

Try something like this.

Get-EventLog -LogName Application -Newest 10 | where{$_.Message -match "fatal"}
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Get-WinEvent doesn't return any data?
Wasim ShaikhCommented:
Get-WinEvent -LogName system -MaxEvents 10 | where{$_.message -match "fatal"}
CaussyRAuthor Commented:
So, when I run just : get-winevent -LogName System  -MaxEvents 10 the Message data is not displayed.

Therefore, I think I need to use the invoke-command to run get-eventlog.
Wasim ShaikhCommented:
are you trying to get result from remote computer? is remote management enabled on computer/s?
where exactly you are running the cmdlets? if the powershell console running as an "Administrator"
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
 (get-winevent -LogName System  -MaxEvents 10).Count
should display 10. If it doesn't, something is wrong. You are executing that on Vista or above?
Steven HarrisPresidentCommented:
Are you by chance running this from a file and missing errors from the console?
CaussyRAuthor Commented:
I am running Windows 7 Enterprise as an Administrator and I have tried running the query as a Domain Admin. I have enabled $PSRemoting on each server and when using  (get-winevent -LogName System  -MaxEvents 10).Count only returns the number 10 as expected and I did substitute .count to .message which also did not work.
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
PS3 allows that usuage of @(some collection).objectproperty, but PS2 does not. W7 by default uses PS2. That is the only possible reason I can find. If I'm correct,
 get-winevent System -max 10 | select message
returns something.
Wasim ShaikhCommented:
since you are trying to retrieve logs from remote computer you need to provide the name of computer in -ComputerName Parameter.

For one server use
Get-WinEvent -ComputerName <your srv name> -LogName system -MaxEvents 10

Open in new window

Replace <your srv name> with the name of server
once your get some data then use to filter
Get-WinEvent -ComputerName <your srv name> -LogName system -MaxEvents 10 | where{$_.message -match "fatal"} 

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.