Windows在$ENV:windir\System32\WDI\LogFiles\StartupInfo\
中创建了一个不错的XML日志文件,它告诉您有关启动应用程序/进程,其CPU使用率,磁盘使用率和加载时间的信息。
我花了一段时间尝试在PowerShell中加载和读取此文件,目的是将数据作为PSObject或Hashtable进行处理。
使用Import-clixml
时出现以下错误:
PS C:\Users> $data = Import-Clixml -Path "C:\Windows\System32\WDI\LogFiles\StartupInfo\StartupInfo1.xml"
Import-Clixml : Element 'Objs' with namespace name 'http://schemas.microsoft.com/powershell/2004/04' was not found. Line 2, position 2.
At line:1 char:9
+ $data = Import-Clixml -Path "C:\Windows\System32\WDI\LogFiles\Startup ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Import-Clixml], XmlException
+ FullyQualifiedErrorId : System.Xml.XmlException,Microsoft.PowerShell.Commands.ImportClixmlCommand
,当我尝试使用[xml]$Data = Get-Content...
进行收集时,它可以工作,但没有提供我期望的结构:
PS C:\Users> [xml]$data = Get-Content -Path "C:\Windows\System32\WDI\LogFiles\StartupInfo\StartupInfo1.xml"
PS C:\Users> $data
xml StartupData
--- -----------
version="1.0" encoding="UTF-16" StartupData
PS C:\Users\alt63> $data.StartupData
IntervalStartMs IntervalEndMs ReadAheadAnalysisTime RurLegacyResourceAttribution
--------------- ------------- --------------------- ----------------------------
138080 228080 0 0
XML内容:
<?xml version="1.0" encoding="UTF-16"?>
<StartupData IntervalStartMs="15383" IntervalEndMs="105383">
<Process Name="C:\Devi" PID="8928" StartedInTraceSec="33.422">
<StartTime>2019/02/19:00:01:48.6792251</StartTime>
<CommandLine><![CDATA["C:\Users\user_a\AppData\Local\slack\Update.exe" --processStart "slack.exe" --process-start-args "--startup"]]></CommandLine>
<DiskUsage Units="bytes">9797632</DiskUsage>
<CpuUsage Units="us">520359</CpuUsage>
<ParentPID>5132</ParentPID>
<ParentStartTime>2019/02/19:00:01:31.1627452</ParentStartTime>
<ParentName>explorer.exe</ParentName>
</Process>
<Process Name="C:\Devic" PID="9064" StartedInTraceSec="34.440">
<StartTime>2019/02/19:00:01:49.6967953</StartTime>
<CommandLine>"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"</CommandLine>
<DiskUsage Units="bytes">11264</DiskUsage>
<CpuUsage Units="us">40602</CpuUsage>
<ParentPID>9012</ParentPID>
<ParentStartTime>2019/02/19:00:01:49.4645583</ParentStartTime>
<ParentName>chrome.exe</ParentName>
</Process>
<ReadAheadAnalysisTime>0</ReadAheadAnalysisTime>
<RurLegacyResourceAttribution>31</RurLegacyResourceAttribution>
</StartupData>
(日志要长得多,为了简洁起见,省略了数据)
两个查询:
谢谢!