按登录类型 2 或登录类型 3 筛选 Get-WinEvent

Get-WinEvent filter by logontype 2 OR logontype 3

我遇到了这个 Get-WinEvent Obtain Interactive Logon Messages Only 并尝试在相同的情况下与 OR 一起玩:

 Get-WinEvent -FilterHashtable @{Path="c:\test.evtx"; id=4624;} | Where-Object {$_.properties[8].value -eq 2} OR {$_.properties[8].value -eq 3}

我想知道这不起作用吗?

如果我有两个不同的 eventid 和两个不同的 where 子句,会发生什么,例如EventId 4624 和登录类型 2 或登录类型 3
OR eventid 1234 和主机名 = localhost.

我需要做的是仅检查 logontype:2 和登录类型 3,并在登录类型为 3(远程)时打印网络详细信息。

OR 在 PowerShell 中无效...您可能是说 -or!

在这种情况下,您的代码最终看起来像这样:

Get-WinEvent -FilterHashtable @{Path="c:\test.evtx"; id=4624;} |
    Where-Object {$_.properties[8].value -eq 2 -OR $_.properties[8].value -eq 3}

另外,我经常发现 -in 运算符在这种情况下更清晰

Get-WinEvent -FilterHashtable @{Path="c:\test.evtx"; id=4624;} |
    Where-Object {$_.properties[8].value -in 2, 3}