如何使用 powershell 从 xml 中过滤以获取启动持续时间?

How to filter from xml to get boot duration using powershell?

所以这是代码,它给出了一个 table 作为输出。

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

如果我想要 Name 中的一个实体记录,例如 BootTime filtered 并输出而不是显示整个 list/table,

应该做出哪些改变?

否则,您能否建议使用 powershell 仅获得 启动持续时间 的任何其他方法?

提前致谢,

只获取启动时间:

$bootevent.Event.EventData.Data | ? name -eq boottime

Name     #text
----     -----
BootTime 30234

顺便说一下,较新的 powershells (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: …

另一个更短的选项:

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

输出:

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