@powershellman8045<\/a><\/p>","upvoteCount":5,"datePublished":"2016-12-20T00:42:11.000Z","url":"https://community.spiceworks.com/t/exclude-specified-event-ids-from-get-winevent-output/548098/1","author":{"@type":"Person","name":"albertsantos2","url":"https://community.spiceworks.com/u/albertsantos2"}},{"@type":"Answer","text":"First thought I had was a Case statement that does nothing for the event IDs you want to ignore.<\/p>","upvoteCount":0,"datePublished":"2016-12-20T13:11:49.000Z","url":"https://community.spiceworks.com/t/exclude-specified-event-ids-from-get-winevent-output/548098/2","author":{"@type":"Person","name":"dwren","url":"https://community.spiceworks.com/u/dwren"}},{"@type":"Answer","text":"
I also had to remove the Level=1,2,3 part out of your Get-WinEvent entry as it was not working for me<\/p>","upvoteCount":0,"datePublished":"2016-12-22T12:21:35.000Z","url":"https://community.spiceworks.com/t/exclude-specified-event-ids-from-get-winevent-output/548098/4","author":{"@type":"Person","name":"tonyorr","url":"https://community.spiceworks.com/u/tonyorr"}},{"@type":"Answer","text":"
Hello Tony. This is great. I will test this out and will let you know how it goes.<\/p>","upvoteCount":0,"datePublished":"2016-12-23T03:12:29.000Z","url":"https://community.spiceworks.com/t/exclude-specified-event-ids-from-get-winevent-output/548098/5","author":{"@type":"Person","name":"albertsantos2","url":"https://community.spiceworks.com/u/albertsantos2"}},{"@type":"Answer","text":"\n\n
<\/div>\n
albertsantos2:<\/div>\n
\nHello Tony. This is great. I will test this out and will let you know how it goes.<\/p>\n<\/blockquote>\n<\/aside>\n
Did that workout for you?<\/p>","upvoteCount":0,"datePublished":"2016-12-27T20:09:19.000Z","url":"https://community.spiceworks.com/t/exclude-specified-event-ids-from-get-winevent-output/548098/6","author":{"@type":"Person","name":"doughnutdestroyer","url":"https://community.spiceworks.com/u/doughnutdestroyer"}},{"@type":"Answer","text":"\n\n
<\/div>\n
Tony7172:<\/div>\n
\nBut you should be able to change this to either -eq for equals or even have a couple linked together i.e. if (($CurrentId -ne ‘7036’) -or ($CurrentId -ne ‘7016’) )<\/p>\n<\/blockquote>\n<\/aside>\n
Hi Tony,<\/p>\n
It works on a single EventID but having a couple of EventIDs linked together does not work. i.e. if (($CurrentId -ne ‘7036’) -or ($CurrentId -ne ‘7016’) ).<\/p>","upvoteCount":0,"datePublished":"2017-01-03T06:59:18.000Z","url":"https://community.spiceworks.com/t/exclude-specified-event-ids-from-get-winevent-output/548098/7","author":{"@type":"Person","name":"albertsantos2","url":"https://community.spiceworks.com/u/albertsantos2"}},{"@type":"Answer","text":"\n\n
<\/div>\n Doughnut Destroyer:<\/div>\n
\n\n\n
<\/div>\n
albertsantos2:<\/div>\n
\nHello Tony. This is great. I will test this out and will let you know how it goes.<\/p>\n<\/blockquote>\n<\/aside>\n
Did that workout for you?<\/p>\n<\/blockquote>\n<\/aside>\n
It did, for a single eventid. Linking 2 or more eventid does not work.<\/p>","upvoteCount":0,"datePublished":"2017-01-03T07:01:03.000Z","url":"https://community.spiceworks.com/t/exclude-specified-event-ids-from-get-winevent-output/548098/8","author":{"@type":"Person","name":"albertsantos2","url":"https://community.spiceworks.com/u/albertsantos2"}},{"@type":"Answer","text":"
I have had a quick look and may have been overcomplicating it a bit.<\/p>\n
Try using the following format for the if statement (replace the EventIds with the ones you want to omit):<\/p>\n
if (($CurrentId -ne ‘7036’) -and ($CurrentId -ne ‘7016’)).<\/p>","upvoteCount":0,"datePublished":"2017-01-03T12:38:49.000Z","url":"https://community.spiceworks.com/t/exclude-specified-event-ids-from-get-winevent-output/548098/9","author":{"@type":"Person","name":"tonyorr","url":"https://community.spiceworks.com/u/tonyorr"}},{"@type":"Answer","text":"\n\n
<\/div>\n
Tony7172:<\/div>\n
\nI have had a quick look and may have been overcomplicating it a bit.<\/p>\n
Try using the following format for the if statement (replace the EventIds with the ones you want to omit):<\/p>\n
if (($CurrentId -ne ‘7036’) -and ($CurrentId -ne ‘7016’)).<\/p>\n<\/blockquote>\n<\/aside>\n
Hey man. This works! Thanks heaps for the help.<\/p>","upvoteCount":0,"datePublished":"2017-01-03T23:17:39.000Z","url":"https://community.spiceworks.com/t/exclude-specified-event-ids-from-get-winevent-output/548098/10","author":{"@type":"Person","name":"albertsantos2","url":"https://community.spiceworks.com/u/albertsantos2"}},{"@type":"Answer","text":"
No problem, Glad it works <\/p>","upvoteCount":0,"datePublished":"2017-01-04T08:01:49.000Z","url":"https://community.spiceworks.com/t/exclude-specified-event-ids-from-get-winevent-output/548098/11","author":{"@type":"Person","name":"tonyorr","url":"https://community.spiceworks.com/u/tonyorr"}}]}}
Hello there. Looking at my code below, what’s the best possible way to exclude specific events from the CSS output generated? What i want is for the script to fetch the list of event ids to be excluded from a text file. Sorry, i really am a beginner in this.
$computers = 'Servers.txt'
$StartDate = (get-date).AddDays(-1)
$logReport = "D:\LogReport\LogReport.html"
$css= "<style>"
$css= $css+ "BODY{ text-align: center; background-color:white;}"
$css= $css+ "TABLE{ font-family: 'Lucida Sans Unicode', 'Lucida Grande', Sans-Serif;font-size: 12px;margin: 10px;width: 100%;text-align: center;border-collapse: collapse;border-top: 7px solid #004466;border-bottom: 7px solid #004466;}"
$css= $css+ "TH{font-size: 13px;font-weight: normal;padding: 1px;background: #cceeff;border-right: 1px solid #004466;border-left: 1px solid #004466;color: #004466;}"
$css= $css+ "TD{padding: 1px;background: ##FFFFFF;border-right: 1px solid #004466;border-left: 1px solid #004466;color: #669;hover:black;}"
$css= $css+ "TD:hover{ background-color:#e5f7ff;}"
$css= $css+ "</style>"
$body = Get-Content $computers | ForEach-Object {
Get-WinEvent -ComputerName $_ -FilterHashtable @{logname=System; Level=1,2,3; starttime=$StartDate}
$body | ConvertTo-HTML -Head $css MachineName,LogName,LevelDisplayName,ID,TimeCreated,Message > $logReport
@powershellman8045
5 Spice ups
dwren
(dwren)
December 20, 2016, 1:11pm
2
First thought I had was a Case statement that does nothing for the event IDs you want to ignore.
tonyorr
(Tony7172)
December 22, 2016, 12:20pm
3
I am not 100% sure of what you are trying to acheive, but you could use an if statement to poulate only the CSS code only with the values of relevence:
I had a quick play around and came up with the below:
$computers = 'C:\Path to servers txt file\Servers.txt'
$StartDate = (get-date).AddDays(-1)
$logReport = "D:\LogReport\LogReport.html"
$OutputStream = @()
$css= "<style>"
$css= $css+ "BODY{ text-align: center; background-color:white;}"
$css= $css+ "TABLE{ font-family: 'Lucida Sans Unicode', 'Lucida Grande', Sans-Serif;font-size: 12px;margin: 10px;width: 100%;text-align: center;border-collapse: collapse;border-top: 7px solid #004466;border-bottom: 7px solid #004466;}"
$css= $css+ "TH{font-size: 13px;font-weight: normal;padding: 1px;background: #cceeff;border-right: 1px solid #004466;border-left: 1px solid #004466;color: #004466;}"
$css= $css+ "TD{padding: 1px;background: ##FFFFFF;border-right: 1px solid #004466;border-left: 1px solid #004466;color: #669;hover:black;}"
$css= $css+ "TD:hover{ background-color:#e5f7ff;}"
$css= $css+ "</style>"
$body = Get-Content $computers
$Body | ForEach {
$Test = Get-WinEvent -ComputerName $_ -FilterHashtable @{logname='System'; starttime=$StartDate}
Foreach ($event in $test) {
$CurrentId = $event.Id
if ($CurrentId -ne '7036' ) {
$outputstream += $Event
}
}
}
$OutputStream | ConvertTo-HTML -Head $css MachineName,LogName,LevelDisplayName,ID,TimeCreated,Message > $logReport
Note that you will need to put the full path of the servers.txt in your $computers variable. The if statment has a ‘-ne’ operator for Not Equals, so it will pull any event that does not equal that particular EventId. But you should be able to change this to either -eq for equals or even have a couple linked together i.e. if (($CurrentId -ne ‘7036’) -or ($CurrentId -ne ‘7016’) )
Just test it in a controlled test setting first i.e. a test server and see if it works the way you want.
tonyorr
(Tony7172)
December 22, 2016, 12:21pm
4
I also had to remove the Level=1,2,3 part out of your Get-WinEvent entry as it was not working for me
Hello Tony. This is great. I will test this out and will let you know how it goes.
Did that workout for you?
Hi Tony,
It works on a single EventID but having a couple of EventIDs linked together does not work. i.e. if (($CurrentId -ne ‘7036’) -or ($CurrentId -ne ‘7016’) ).
It did, for a single eventid. Linking 2 or more eventid does not work.
tonyorr
(Tony7172)
January 3, 2017, 12:38pm
9
I have had a quick look and may have been overcomplicating it a bit.
Try using the following format for the if statement (replace the EventIds with the ones you want to omit):
if (($CurrentId -ne ‘7036’) -and ($CurrentId -ne ‘7016’)).
Tony7172:
I have had a quick look and may have been overcomplicating it a bit.
Try using the following format for the if statement (replace the EventIds with the ones you want to omit):
if (($CurrentId -ne ‘7036’) -and ($CurrentId -ne ‘7016’)).
Hey man. This works! Thanks heaps for the help.
tonyorr
(Tony7172)
January 4, 2017, 8:01am
11
No problem, Glad it works