i am trying to Filter out some EventIDs from Get-Event log like this :
...More code here
Get-EventLog -LogName $_ -EntryType Warning,Error |
Where-Object {$_.EventID -ne '0|1|2|3|4|7|8|9|10|14|15|17...'}
However i am running into trouble with the comparator, using -ne simply does not Filter anything out, and if i use -notmatch, it returns only one result, and i have confirmed there are a lot that it's skipping. Not sure what i am missing and why it's -ne is not working at all, any help is appreciated! Thanks a lot in advance !
Your current code:
is currently checking if the ID is literally
0|1|2|3|4|7|8|9|10|14|15|17...
.To check if the ID is one of the values specified, you need to use
-in
operator, as suggested in the comments:For future reference, please check
about_Comparison_Operators
from PowerShell documentation.