Link to home
Start Free TrialLog in
Avatar of VIVEKANANDHAN_PERIASAMY
VIVEKANANDHAN_PERIASAMY

asked on

Need a powershell script which collect only distinct error logs from the list of servers

Need a powershell script which collect only distinct error logs (from application logs)from the list of servers.

Application logs looking for only for below event source
event source like *SQL*
Avatar of Haresh Nikumbh
Haresh Nikumbh
Flag of India image

Get-EventLog -LogName "application" | Where-Object {$_.source -like "*SQL*"} 

Open in new window



http://www.mssqltips.com/sqlservertip/2911/using-powershell-to-access-event-logs-for-sql-server/
Avatar of VIVEKANANDHAN_PERIASAMY
VIVEKANANDHAN_PERIASAMY

ASKER

Thanks, I knew this but problem i'm facing is, I need only distinct sql error event id, with the description.
are you saying you want just a couple of the properties from the output?


Get-EventLog -LogName "application" | ? {$_.source -like "*SQL*"}  | select InstanceID, Message

Open in new window

Get-EventLog -LogName "application" | Where-Object {$_.source -like "*SQL*"} | Where-Object {$_.entryType -Match "Error"}

also check it out below link .. multiple options are given.

Powershell script for SQL
No. In case if i have error like below in the event viewer

3041 -Backup failed.
18752 - SQL Job failed.
3041 -Backup failed.
3041 -Backup failed.
18752 - SQL Job failed.
3041 -Backup failed.
18752 - SQL Job failed.
3041 -Backup failed.
18752 - SQL Job failed.
18752 - SQL Job failed.

My output should have only 2 entries.
3041 -Backup failed.
18752 - SQL Job failed.


I'm looking for Distinct error event id from event logs
try this?
Get-EventLog -LogName "application" | ? {$_.source -like "*SQL*"}  | select InstanceID, Message | sort instanceid | get-unique

Open in new window

how to get the event id, i'm not looking for instanceid. And by giving unique,it gives only one record eventhough there many unique errors.

Base idea ,is to find distinct error logs for sql server & sql server agents
instanceid is the event id.

i think there is a pretty substantial disconnect between us at this point, and I apologize for not understanding what you are asking for...

get-unique should return unique records: in this case, unique eventID/Description combinations. in your previous post you gave an example of 10 entries in the even log that you expect 2 results for from this query, does this not accomplish it?
So how got it to near solution.

Get-EventLog -LogName "application" | Where-Object {$_.source -like "*SQL*"} | Where-Object {$_.entryType -Match "Error"}  | Group-Object eventid 

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India 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
Thanks, i need to get an description alone. How to do that...
You can use where condition to match the description property for specific words. For example..  

Get-EventLog -LogName "application" | ? {$_.source -like "*SQL*" -and $_.entryType -Match "Error" -and $_.Message -Match "Failed"}  | Select EventID,MachineName,Source,Message -Unique

Open in new window