如何使用Powershell从xml进行过滤以获取启动持续时间?

问题描述 投票:1回答:2

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

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

如果我想从名称中像BootTime这样的一个实体记录进行过滤并输出而不是显示整个列表/表,

应进行哪些更改?

还可以建议使用Powershell获得启动持续时间的任何其他方法吗?

谢谢,

xml powershell boot event-log get-winevent
2个回答
2
投票

仅获得启动时间:

$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: …

1
投票

另一个更简短的选项:

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

输出:

Name     #text 
----     ----- 
BootTime 123355
© www.soinside.com 2019 - 2024. All rights reserved.