Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在wevtutil中使用xpath检索特定时间以来的事件_Xpath_Wevtutil - Fatal编程技术网

如何在wevtutil中使用xpath检索特定时间以来的事件

如何在wevtutil中使用xpath检索特定时间以来的事件,xpath,wevtutil,Xpath,Wevtutil,我不知道。我看过W3教程,但它们似乎不起作用 我正在使用wevtutil从windows事件日志中提取事件 我使用的是Windows Server 2008 R2 Enterprise 如果使用以下命令仅列出最后三个事件: wevtutil qe Application /c:3 /rd:true /e:root 我得到以下结果: <?xml version="1.0"?> <root> <Event xmlns="http://schemas.microso

我不知道。我看过W3教程,但它们似乎不起作用

我正在使用wevtutil从windows事件日志中提取事件

我使用的是Windows Server 2008 R2 Enterprise

如果使用以下命令仅列出最后三个事件:

wevtutil qe Application /c:3 /rd:true /e:root
我得到以下结果:

<?xml version="1.0"?>
<root>
  <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
      <Provider EventSourceName="Software Protection Platform Service" Guid="{E23B33B0-C8C9-472C-A5F9-F2BDFEA0F156}" Name="Microsoft-Windows-Security-SPP"/>
      <EventID Qualifiers="16384">902</EventID>
      <Version>0</Version>
      <Level>0</Level>
      <Task>0</Task>
      <Opcode>0</Opcode>
      <Keywords>0x80000000000000</Keywords>
      <TimeCreated SystemTime="2016-04-22T08:20:30.000000000Z"/>
      <EventRecordID>49232</EventRecordID>
      <Correlation/>
      <Execution ThreadID="0" ProcessID="0"/>
      <Channel>Application</Channel>
      <Computer>EU9742K8WEB01.emea.sitel-world.net</Computer>
      <Security/>
    </System>
    <EventData>
      <Data>6.1.7601.17514</Data>
    </EventData>
  </Event>
  <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
      <Provider EventSourceName="Software Protection Platform Service" Guid="{E23B33B0-C8C9-472C-A5F9-F2BDFEA0F156}" Name="Microsoft-Windows-Security-SPP"/>
      <EventID Qualifiers="16384">1003</EventID>
      <Version>0</Version>
      <Level>4</Level>
      <Task>0</Task>
      <Opcode>0</Opcode>
      <Keywords>0x80000000000000</Keywords>
      <TimeCreated SystemTime="2016-04-22T08:20:30.000000000Z"/>
      <EventRecordID>49231</EventRecordID>
      <Correlation/>
      <Execution ThreadID="0" ProcessID="0"/>
      <Channel>Application</Channel>
      <Computer>EU9742K8WEB01.emea.sitel-world.net</Computer>
      <Security/>
    </System>
    <EventData>
      <Data>55c92734-d682-4d71-983e-d6ec3f16059f</Data>
      <Data>1: 0cb1d6b4-3c07-487f-82fc-886d44a646aa, 1, 0 [(0 [0xC004F014, 0, 0], [(?)(?)(?)(?)(?)(?)])(1 )(2 )]2: 2d727362-1f80-4a74-9e4d-e7c79826e659, 1, 0 [(0 [0xC004F014, 0, 0], [(?)(?)(?)(?)(?)(?)])(1 )(2 )]3: 4bcc8879-e699-4159-a810-f829566662ca, 1, 0 [(0 [0xC004F014, 0, 0], [(?)(?)(?)(?)(?)(?)])(1 )(2 )]4: 620e2b3d-09e7-42fd-802a-17a13652fe7a, 1, 1 [(0 [0x00000000, 1, 0], [(?)(?)( 1 0x00000000 30 0 msft:rm/algorithm/volume/1.0 0x00000000 254400)(?)(?)(?)])(1 )(2 )]5: 6a4bd364-4b60-4856-a727-efb59d94348e, 1, 0 [(0 [0xC004F014, 0, 0], [(?)(?)(?)(?)(?)(?)])(1 )(2 )]6: 8fe15d04-fc66-40e6-bf34-942481e06fd8, 1, 0 [(0 [0xC004F014, 0, 0], [(?)(?)(?)(?)(?)(?)])(1 )(2 )]7: b297426d-464d-4af1-abb2-3474aeecb878, 1, 0 [(0 [0xC004F014, 0, 0], [(?)(?)(?)(?)(?)(?)])(1 )(2 )]8: c60b048b-8071-4532-8398-f15f4c981861, 1, 0 [(0 [0xC004F014, 0, 0], [(?)(?)(?)(?)(?)(?)])(1 )(2 )]9: c74dc7f6-ea35-4bd7-9776-333ab5dddae6, 1, 0 [(0 [0xC004F014, 0, 0], [(?)(?)(?)(?)(?)(?)])(1 )(2 )]10: c99b641f-c4ea-4e63-bec3-5ed2ccd0f357, 1, 0 [(0 [0xC004F014, 0, 0], [(?)(?)(?)(?)(?)(?)])(1 )(2 )]11: ea36520d-fbfe-4042-acd8-fe926781b615, 1, 0 [(0 [0xC004F014, 0, 0], [(?)(?)(?)(?)(?)(?)])(1 )(2 )]</Data>
    </EventData>
  </Event>
  <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
    <System>
      <Provider EventSourceName="Software Protection Platform Service" Guid="{E23B33B0-C8C9-472C-A5F9-F2BDFEA0F156}" Name="Microsoft-Windows-Security-SPP"/>
      <EventID Qualifiers="16384">1066</EventID>
      <Version>0</Version>
      <Level>4</Level>
      <Task>0</Task>
      <Opcode>0</Opcode>
      <Keywords>0x80000000000000</Keywords>
      <TimeCreated SystemTime="2016-04-22T08:20:30.000000000Z"/>
      <EventRecordID>49230</EventRecordID>
      <Correlation/>
      <Execution ThreadID="0" ProcessID="0"/>
      <Channel>Application</Channel>
      <Computer>EU9742K8WEB01.emea.sitel-world.net</Computer>
      <Security/>
    </System>
    <EventData>
      <Data>C:\Windows\system32\sppwinob.dll, msft:spp/windowsfunctionality/agent/7.0, 0x00000000, 0x00000000C:\Windows\system32\sppobjs.dll, msft:rm/algorithm/phone/1.0, 0x00000000, 0x00000000C:\Windows\system32\sppobjs.dll, msft:rm/algorithm/pkey/2005, 0x00000000, 0x00000000C:\Windows\system32\sppobjs.dll, msft:spp/TaskScheduler/1.0, 0x00000000, 0x00000000C:\Windows\system32\sppobjs.dll, msft:spp/volume/services/kms/1.0, 0x00000000, 0x00000000C:\Windows\system32\sppobjs.dll, msft:spp/volume/services/kms/licenserenewal/1.0, 0x00000000, 0x00000000</Data>
    </EventData>
  </Event>
</root>
结果是:

<root>
</root>

如果将xpath更改为
Event/System/TimeCreated
,则得到的xml与上面列出的相同

所以有两个问题:

  • 我如何只获取TimeCreated元素而不获取所有其他元素(这一个对我来说不太重要)

  • 如何检索SystemTime属性位于两个指定值之间的位置

  • 如果有人能向我解释为什么我不能像W3教程中建议的那样使用TimeCreated,那也很好


    教程可在

    找到,不要紧,可在其他地方找到:

    *[System[TimeCreated[@SystemTime>='2016-04-22T00:00:00' and @SystemTime<'2016-04-22T01:00:00']]]
    
    *[System[TimeCreated[@SystemTime>='2016-04-22T00:00:00'和@SystemTime t.xml
    
    首先,Windows事件日志。通用XPath教程将帮助您掌握表达式语法的基本原理,这很好,但您会遇到复杂事件日志查询上下文中的限制,因此请记住这一点

    在您的情况下,大于运算符和小于运算符就足够了,并且它们是受支持的,因此以下工作(变量仅用于可读性目的):

    set“FROM=2016-04-01T00:00:00”
    设置“至=2016-04-21T00:00:00”
    设置“XPATH=Event/System/TimeCreated[@SystemTime>='%FROM%'和@SystemTime<'%TO%'”
    wevtutil qe应用程序/c:30/rd:true/e:root/q:“%XPATH%”
    
    请注意,时间戳仅接受
    YYYY-MM-DDTHH:NN:SS
    格式,即仅使用日期不起作用

    还请注意,不支持提取部分事件数据。从技术上讲,上面的XPath仅选择
    TimeCreated
    元素,但按照事件日志查询的工作方式,将返回完整的事件数据结构


    要进一步减少返回的数据,请使用常规的XML处理工具。例如,Powershell有一组用于处理XML的工具。

    XPath不太清楚应该如何写,但已经很接近了。
    *[System[TimeCreated[@SystemTime>='2016-04-22T00:00:00' and @SystemTime<'2016-04-22T01:00:00']]]
    
    wevtutil qe Application /q:"*[System[TimeCreated[@SystemTime>='2016-04-22T00:00:00 ' and @SystemTime<'2016-04-22T01:00:00']]]" /f:RenderedXml > t.xml
    
    set "FROM=2016-04-01T00:00:00"
    set "TO=2016-04-21T00:00:00"
    set "XPATH=Event/System/TimeCreated[@SystemTime >= '%FROM%' and @SystemTime < '%TO%']"
    
    wevtutil qe Application /c:30 /rd:true /e:root /q:"%XPATH%"