adriansroaming
adriansroaming

Reputation: 33

Get-WinEvent -FilterHashTable with multiple IDs in a variable not working

This work for me:

Get-WinEvent -FilterHashTable @{Logname = "ForwardedEvents" ; ID = 4625,4740}

(.... results I expect...)

This works:

$EventId = "4625"

Get-WinEvent -FilterHashTable @{Logname = "ForwardedEvents" ; ID = $EventId}

This doesn't work:

$EventId = "4625,4740"

Get-WinEvent -FilterHashTable @{Logname = "ForwardedEvents" ; ID = $EventId}

Error...

  Get-WinEvent : No events were found that match the specified selection criteria.
At line:1 char:13
+ Get-WinEvent <<<<  -FilterHashTable @{Logname = "ForwardedEvents" ; ID = $EventIds}
+ CategoryInfo          : ObjectNotFound: (:) [Get-WinEvent], Exception
+ FullyQualifiedErrorId : NoMatchingEventsFound,Microsoft.PowerShell.Commands.GetWinEventCommand

Can anyone help please?

Upvotes: 3

Views: 16861

Answers (1)

Matt
Matt

Reputation: 46710

Just change it to $EventId = 4625,4740 (remove the quotes) and that should work. Looking at the documentation for Get-WinEvent and the -FilterHashTable we see:

-- ID=<Int32[]>

So it is expecting an array and not a string.

Upvotes: 7

Related Questions