Link to home
Start Free TrialLog in
Avatar of Member_2_6492660_1
Member_2_6492660_1Flag for United States of America

asked on

Powershell Event Error Details

I have over 100 Windows servers from Windows 2003 to Windows 2012

We need to review the Event logs and a daily basis. We must use event viewer review the application and system logs.
This takes a while to expand the event log using MMC or Server Manager views.

I be playing around with Powershell scripts to handle this which is faster

So I use this command which lists the application Warnings Only from the last twenty four hours.  
I use Level=2 for Errors also do this for both the application and system event logs.


This outputs see below  and that is ok

 get-winevent -FilterHashTable @{LogName='Application'; Level=3; StartTime=(get-date).addhours(-24)}


TimeCreated                   ProviderName                                             Id Message
-----------                   ------------                                             -- -------
10/2/2015 12:09:26 PM         Microsoft-Windows-Certific...                            64 Certificate for local syst...
10/2/2015 4:09:25 AM          Microsoft-Windows-Certific...                            64 Certificate for local syst...
10/1/2015 8:09:24 PM          Microsoft-Windows-Certific...                            64 Certificate for local syst...

This looks good

My question is how do I display the details of Event Id 64 using power shell

I only want to view the last occurrence I have only been able to get a long list of all instances.

Our management here is not keen on elaborate scripts they like us to use command line so we remember the commands

Every day the events will be different so maybe a short script where I can just add the event id as input would be nice.

Thoughts

Thanks
Avatar of footech
footech
Flag of United States of America image

What do you mean by "details"?
If you just want the message, use Select-Object.
If you only want event ID 64, include ID in your filterhashtable.
If you want to limit the number of events retrieved, use the -MaxEvents parameter of Get-WinEvent.
Avatar of Member_2_6492660_1

ASKER

footech

thanks for responding


this is what I mean by full details

Log Name:      Application
Source:        Microsoft-SharePoint Products-SharePoint Server Search
Date:          9/6/2015 5:56:41 AM
Event ID:      14
Task Category: Gatherer
Level:         Warning
Keywords:      
User:          xxx\spservices
Computer:      SERV013.FQDN.com
Description:
The start address http://sharepointtgcs.com cannot be crawled.

Context: Application 'Search_Service_Application', Catalog 'Portal_Content'

Details:
      An unrecognized HTTP response was received when attempting to crawl this item. Verify whether the item can be accessed using your browser.   (0x80041204)
Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
  <System>
    <Provider Name="Microsoft-SharePoint Products-SharePoint Server Search" Guid="{C8263AFE-83A5-448C-878C-1E5F5D1C4252}" />
    <EventID>14</EventID>
    <Version>14</Version>
    <Level>3</Level>
    <Task>137</Task>
    <Opcode>0</Opcode>
    <Keywords>0x4000000000000000</Keywords>
    <TimeCreated SystemTime="2015-09-06T09:56:41.851264900Z" />
    <EventRecordID>57936</EventRecordID>
    <Correlation />
    <Execution ProcessID="1512" ThreadID="9160" />
    <Channel>Application</Channel>
    <Computer>SERV013.FQDN.com</Computer>
    <Security UserID="S-1-5-21-3054588571-1341459584-784128302-4607" />
  </System>
  <EventData>
    <Data Name="string0">http://sharepointtgcs.com</Data>
    <Data Name="string1">

Context: Application 'Search_Service_Application', Catalog 'Portal_Content'

Details:
      An unrecognized HTTP response was received when attempting to crawl this item. Verify whether the item can be accessed using your browser.   (0x80041204)</Data>
  </EventData>
</Event>




so when I get the list of event I would like to run another command to show the entire event message

do you have an example to display the event ?
Footech

tried this

Get-WinEvent -FilterHashtable @{ LogName = "Application"; id = 1001; -maxevents=1}
At line:1 char:68
+ ... nEvent -FilterHashtable @{ LogName = "Application"; id = 1001; -maxev ...
+                                                                  ~
The hash literal was incomplete.
At line:1 char:82
+ ... -FilterHashtable @{ LogName = "Application"; id = 1001; -maxevents=1}
+                                                                         ~
Unexpected token '}' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : IncompleteHashLiteral
So you want to display all events using the table format, e.g.
TimeCreated                   ProviderName                                             Id Message
-----------                   ------------                                             -- -------
10/2/2015 12:09:26 PM         Microsoft-Windows-Certific...                            64 Certificate for local syst...
10/2/2015 4:09:25 AM          Microsoft-Windows-Certific...                            64 Certificate for local syst...
10/1/2015 8:09:24 PM          Microsoft-Windows-Certific...                            64 Certificate for local syst...

Open in new window

and then you want to display everything for just one of those events?

If so, for that last display, you'd either have to re-do the query, or have saved the previous results so that you can then just display one.  There's no exact equivalent to the view you get in Event Viewer, basically you'd just want to show all properties (think Format-List *).

The -maxevents parameter is not part of the hashtable.
Confused now

Is there a way to display a single event error? And only the last occurrence?

Example please?
ASKER CERTIFIED SOLUTION
Avatar of footech
footech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
FooTech

That worked and is what I was looking for

Now I am off to setting up the script to except input so I can display any event Id I come across

If I have any issues I ll post another one

Thanks again