【问题标题】:How to filter from xml to get boot duration using powershell?如何从 xml 过滤以使用 powershell 获取启动持续时间?
【发布时间】:2020-04-12 15:37:31
【问题描述】:

所以这里是代码,它提供了一个表格作为输出。

$bootevents = Get-WinEvent -FilterHashtable @{logname="Microsoft-Windows-Diagnostics-Performance/Operational"; id=100} $bootevent = [xml]$bootevents[0].ToXml() $bootevent.Event.EventData.Data

如果我希望 Name 中的一个实体记录(例如 BootTime)被过滤 并输出,而不是显示整个列表/表格, p>

应该做哪些改变?

您能否建议任何其他方法来使用 powershell 获得 启动持续时间

提前致谢,

【问题讨论】:

    标签: xml powershell boot event-log get-winevent


    【解决方案1】:

    仅获取启动时间:

    $bootevent.Event.EventData.Data | ? name -eq boottime
    
    Name     #text
    ----     -----
    BootTime 30234
    

    顺便说一句,较新的 powershell (6, 7) 可以过滤命名的 eventdata 数据字段。有些过滤器可以使用通配符。但是日志名有 256 个元素的限制。

    Get-WinEvent @{logname='*Diagnostics-Performance*'; boottime=30234}
    
    
       ProviderName: Microsoft-Windows-Diagnostics-Performance
    
    TimeCreated                     Id LevelDisplayName Message
    -----------                     -- ---------------- -------
    4/12/2020 1:11:05 PM           100 Warning          Windows has started up: …
    

    【讨论】:

      【解决方案2】:

      另一个更短的选项:

      $bootevent.SelectSingleNode("//*[@Name='BootTime']")
      

      输出:

      Name     #text 
      ----     ----- 
      BootTime 123355
      

      【讨论】:

      • 是的,我正在寻找这个特殊的声明 (.SelectSingleNode).. ..非常感谢.. (╭?ᵔ◡ᵔ)╭?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-02
      • 1970-01-01
      • 2021-12-27
      • 1970-01-01
      • 1970-01-01
      • 2011-11-05
      相关资源
      最近更新 更多