# Specific event to monitor and save.

**URL:** <https://forums.powershell.org/t/specific-event-to-monitor-and-save/15354>\
**Category:** PowerShell Help\
**Created:** [December 8, 2020, 1:55am UTC](https://forums.powershell.org/t/specific-event-to-monitor-and-save/15354 "2020-12-08T01:55:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tobias-hallman](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@tobias-hallman](https://forums.powershell.org/u/tobias-hallman)\
**Post date:** [December 8, 2020, 1:55am UTC](https://forums.powershell.org/t/specific-event-to-monitor-and-save/15354/1 "2020-12-08T01:55:06Z")

</div>

Hi i need some help. google have not been sucessful in doing so.

&nbsp;

im trying to create a simple powershell script that will get the specific event from Security logs evenID 12 and 29.

so i created this.

$number = 1

Do {

$computer = Get-Content ‘\*\*\*\*\NETLOGON\Files\Smartakort events\servrar.txt’

foreach ($Machine in $computer )

{

Get-Eventlog -Logname Security -ComputerName $Machine -newest 1000 |

Where-Object {$\_.EventID -eq ‘19’}

Format-Table MachineName, Source, EventID, Message -auto

}

write-host “Run” $number

$number++

sleep 60

} While ($number -le ‘1440’)

now this work for the 1 even. but if i wanna get 2 event IDs i have tried a number of Diffrent ways but im only geting 0 result an error are only one of the two queries.

exmp: Where-Object {$\_.EventID -eq ‘19’ -or ‘29’} i even tried doing the Where-Object statment twice. to no result.

is it just the way powershell work that it cant in this instance sort multiple values from the result of “get-events”

&nbsp;

thanks for all the help i can get.

&nbsp;

---

<div class="post-metadata">

**Author:** ![ralphmwr](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/ralphmwr/32/1064_2.png) [@ralphmwr](https://forums.powershell.org/u/ralphmwr)\
**Post date:** [December 8, 2020, 3:06am UTC](https://forums.powershell.org/t/specific-event-to-monitor-and-save/15354/2 "2020-12-08T03:06:16Z")

</div>

Piping Get-EventLog to Where-Object could be painfully slow since there are a lot of objects to evaluate. Get-EventLog has a parameter InstanceID that will take an array of Event ID numbers. Recommend you use that instead. I prefer Get-WinEvent thought because it can read the newer Windows logs. Here is an example of how you can use either one in your situation.

```
#Using Get-WinEvent
$Filter = @{
    Logname = "Security"
    ID = 12, 29
}
Get-WinEvent -FilterHashtable $Filter

#Using Get-EventLog
Get-EventLog -LogName Security -InstanceId 12, 29
```

Recommend reviewing docs:

[Get-WinEvent](https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Diagnostics/Get-WinEvent?view=powershell-5.1)

[WinEvent queries with filterhashtable](https://docs.microsoft.com/en-us/powershell/scripting/samples/creating-get-winevent-queries-with-filterhashtable?view=powershell-7.1)

[Get-EventLog](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-eventlog?view=powershell-5.1)

&nbsp;

---

<div class="post-metadata">

**Author:** ![tobias-hallman](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@tobias-hallman](https://forums.powershell.org/u/tobias-hallman)\
**Post date:** [December 8, 2020, 4:10am UTC](https://forums.powershell.org/t/specific-event-to-monitor-and-save/15354/3 "2020-12-08T04:10:23Z")

</div>

thanks alot, that worked great. did just what i wanted. and thanks for the little lesson that speeded up the process by alot.

&nbsp;

---

<div class="post-metadata">

**Author:** ![tonyd](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/tonyd/32/1041_2.png) [@tonyd](https://forums.powershell.org/u/tonyd)\
**Post date:** [December 8, 2020, 7:42am UTC](https://forums.powershell.org/t/specific-event-to-monitor-and-save/15354/4 "2020-12-08T07:42:51Z")

</div>

Get-WinEvent using a hash table as Mike has pointed out will be substantially faster then Get-EventLog. In my opinion, you should only use Get-EventLog if your Powershell version does not support Get-WinEvent.

Just my $.02

Also, you wrote: exmp: Where-Object {$\_.EventID -eq ’19’ -or ’29’} i even tried doing the Where-Object statment twice. to no result.

I do believe you should have used `{$.EventID -eq ’19’ -or $.EventID -eq ’29’} `

---

<div class="post-metadata">

**Author:** ![ralphmwr](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/ralphmwr/32/1064_2.png) [@ralphmwr](https://forums.powershell.org/u/ralphmwr)\
**Post date:** [December 8, 2020, 7:59am UTC](https://forums.powershell.org/t/specific-event-to-monitor-and-save/15354/5 "2020-12-08T07:59:02Z")

</div>

TonyD05 makes a great point regarding logic operators -or in this case. I see this error all the time. When you use a logic operator, both sides of the operator must independently evaluate to $true or $false. Any value other than 0, “” or $null will evaluate to $true.

```
PS C:\WINDOWS\system32> [bool]29
True

PS C:\WINDOWS\system32> [bool]0
False
```

So in essence your Where-Object clause would evaluate to {$\_ -eq 19 -or $true} meaning that came over the pipeline would continue down the pipe since only one side of the -or needs to be true.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:28pm UTC](https://forums.powershell.org/t/specific-event-to-monitor-and-save/15354/6 "2024-05-16T20:28:13Z")

</div>

Closed on May 16, 2024, 8:28pm UTC


