0

我需要从 Windows 7 工作站中提取本地登录/注销列表。我已经保存了 evtx 格式的安全事件日志副本,但我遇到了一些问题。

以下 powershell 提取 ID4624或的所有事件4634

Get-WinEvent -Path 'C:\path\to\securitylog.evtx' | where {$_.Id -eq 4624 -or $_.Id -eq 4634}

然后我只想过滤logon type = 2 (local logon). 管道到:

 | where {$_.properties[8].value -eq 2}

但是似乎删除了所有id=4634(注销)事件。

即使对于事件id = 4624事件,也不存在用户 ID。例如管道:

 | select-object -property Timecreated,TaskDisplayName,MachineName,userid

或以其他方式连接到Export-Csvuserid则为空白。

两个问题是:

  1. 为什么 id 为 4634 的事件在通过管道传输到 where 时会丢失{$_.properties[8].value -eq 2}
  2. 为什么是userid空的?我怎样才能得到userid
4

2 回答 2

0
  1. 请注意,8 不是幻数。它是 4624 事件定义的 XML 中的第 9 个属性(索引从 0 开始)。如果您打开详细信息选项卡并切换到 XML 视图,您可以在事件查看器中看到它。查看 4634 事件时,您可以看到 Logon Type 属性现在是第 5 个 - 因此您可能希望将查询修改为:

    其中 {{$ .Id -eq 4624 -and $ .properties[8] -eq 2} -or {$ .Id -eq 4634 -and $ .properties[4] -eq 2}}

  2. 只是没有为这些事件定义用户 ID。您可能希望查看 XML 中定义的 TargetUserName 属性(第 6 个属性)。

于 2016-07-26T07:33:19.103 回答
0

好的,这就是我最终的结果。它打印出逗号分隔的值:

$evts = Get-WinEvent -Path 'C:\path\to\securitylog.evtx' | where {($_.Id -eq 4624 -and $_.properties[8].value -eq 2) -or ($_.Id -eq 4634 -and $_.properties[4].value -eq 2) }
foreach ($e in $evts)
{
    # get the attributes
    $ds = $e.TimeCreated
    $tdn = $e.TaskDisplayName
    $mn = $e.MachineName

    # userid will vary depending on event type:
    if($e.Id -eq 4624) { $userid = $e.properties[5].value }
    if($e.Id -eq 4634) { $userid = $e.properties[1].value }

    write-host ("{0},{1},{2},{3}" -f [string]$ds,[string]$tdn,[string]$mn,[string]$userid)
}
于 2016-07-27T00:40:34.893 回答