如何使用powershell从xml中筛选以获得启动持续时间?

如何使用powershell从xml中筛选以获得启动持续时间?,xml,powershell,boot,event-log,get-winevent,Xml,Powershell,Boot,Event Log,Get Winevent,这是代码,它给出了一个表作为输出 $bootevents=Get WinEvent-FilterHashtable@{logname=“Microsoft Windows诊断性能/操作”;id=100} $bootevent=[xml]$bootevents[0].ToXml() $bootevent.Event.EventData.Data 如果我希望Name中的一条实体记录(如引导时间)被过滤并输出,而不是显示整个列表/表格 应该做什么改变 您还可以建议使用powershell获得启动持续时

这是代码,它给出了一个表作为输出

$bootevents=Get WinEvent-FilterHashtable@{logname=“Microsoft Windows诊断性能/操作”;id=100}
$bootevent=[xml]$bootevents[0].ToXml()
$bootevent.Event.EventData.Data

如果我希望Name中的一条实体记录(如引导时间)被过滤并输出,而不是显示整个列表/表格

应该做什么改变

您还可以建议使用powershell获得启动持续时间的其他方法吗


提前感谢,

只需获取引导时间:

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

要获得启动时间,请执行以下操作:

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

另一个较短的选项:

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

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

另一个较短的选项:

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

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

是的,我在找这个特殊的语句(.SelectSingleNode)。。谢谢。。(╭是的,我正在寻找这个特殊的声明(.SelectSingleNode)…非常感谢(╭