I’m just starting to use hashtables for filtering events.
This example works great and lets me get specific events from the log. However the limitation for extracting events is set by maximum number of events to check, -MaxEvents. Not by, say, events two days ago or last week.
Get-WinEvent -FilterHashtable @{LogName="System";ID=301,302,304,308,101,103,108} -MaxEvents 50
The output from the above has a TimeCreated column but I’ve found no way to incorporate TimeCreated into the hashtable and do a relative test for on or after TimeCreated, on or before TimeCreated, etc. For example:
Get-WinEvent -FilterHashtable @{LogName="System";ID=301,302,304,308,101,103,108;TimeCreated>"2/28/2022"}
is not a valid expression.
This next works, but obviously is not using the hashtable to filter events by date:
Get-WinEvent -FilterHashtable @{LogName="System";ID=301,302,304,308,101,103,108} | Where-Object { $_.TimeCreated -ge "2/28/2022"}
Is there a way to do relative filtering with a hashtable? If there is, please explain, provide link, etc.
Thanks.