get "wevtutil epl test.evtx /q:" 利用多个选择来保存一个事件日志文件

get "wevtutil epl test.evtx /q:" to utilize multiple selects to save one event log file

我试图通过创建自定义视图,然后将其另存为 evtx 文件,基本上完成与事件查看器相同的操作。这是我目前所拥有的以及通过在事件查看器中创建自定义视图生成的自定义 XML。也使用 powershell。

$queryXML =
 Path="Application"
 Path="Application">*[System[Provider[@Name='Application'] and (Level=1  or Level=2 or Level=3)]]
 Path="Security">*[System[Provider[@Name='Application'] and (Level=1  or Level=2 or Level=3)]]
 Path="Setup">*[System[Provider[@Name='Application'] and (Level=1  or Level=2 or Level=3)]]
 Path="System">*[System[Provider[@Name='Application'] and (Level=1  or Level=2 or Level=3)]]
 Path="ForwardedEvents">*[System[Provider[@Name='Application'] and (Level=1  or Level=2 or Level=3)]]

 wevtutil epl C:\Users\user\Desktop\test.evtx "/q: $queryXML"

-

<QueryList>
<Query Id="0" Path="Application">
<Select Path="Application">*[System[(Level=1  or Level=2)]]</Select>
<Select Path="Security">*[System[(Level=1  or Level=2)]]</Select>
<Select Path="Setup">*[System[(Level=1  or Level=2)]]</Select>
<Select Path="System">*[System[(Level=1  or Level=2)]]</Select>
<Select Path="ForwardedEvents">*[System[(Level=1  or Level=2)]]</Select>
</Query>
</QueryList>

想出了一个办法。将查询 xml 保存为 .txt 文件,然后不要像 "system" 那样指定事件日志名称,而是使用带有查询的 .txt 文件的路径。

为了进一步扩展已接受的解决方案,您将 XML 结构化查询保存为一个文件(例如“SQ.xml”),然后像这样更改您的 wevtutil 语句:

wevtutil epl SQ.xml temp.evtx /sq:true

这告诉 wevtutil 使用保存在 SQ.xml 中的 XML 查询并将日志导出到名为 temp.evtx 的文件中。您必须指定 /sq:true 以告诉它查询结构化查询文件。

结构化查询格式主要是 XPath,但 Windows 对其进行了一些细微的调整。更多信息可以 found here。例如:

 <QueryList>
  <Query Id="0">
    <Select Path="System">*[System[TimeCreated[@SystemTime &gt;= '2022-04-22T05:00:00' and @SystemTime &lt;= '2022-04-22T15:00:00']]]</Select>
    <Select Path="Application">*[System[TimeCreated[@SystemTime &gt;= '2022-04-22T05:00:00' and @SystemTime &lt;= '2022-04-22T15:00:00']]]</Select>
  </Query>
</QueryList>

以上查询获取今天(4 月 22 日世界标准时间上午 5 点到下午 3 点)的系统和应用程序日志文件。请注意,因为这是 XML,必须对大于号和小于号进行编码。