PowerShell 技能连载 - 寻找开始时间退化

具有管理员权限的Windows系统可以访问在启动过程中收集到的诊断数据。Windows会记录每个服务和子系统的启动时间和降级时间(以毫秒为单位)。通过这些数据,您可以识别出需要花费过多时间来启动的服务可能存在的问题。

以下是一个脚本,它读取相应的日志文件条目并返回测量得到的启动时间:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#requires -RunAsAdmin

$Days = 180

$machineName = @{
Name = 'MachineName'
Expression = { $env:COMPUTERNAME }
}

$FileName = @{
Name = 'FileName';
Expression = { $_.properties[2].value }
}

$Name = @{
Name = 'Name';
Expression = { $_.properties[4].value }
}

$Version = @{
Name = 'Version'
Expression = { $_.properties[6].value }
}

$TotalTime = @{
Name = 'TotalTime'
Expression = { $_.properties[7].value }
}

$DegradationTime = @{
Name = 'DegradationTime'
Expression = { $_.properties[8].value }
}

Get-WinEvent -FilterHashtable @{
LogName='Microsoft-Windows-Diagnostics-Performance/Operational'
Id=101
StartTime = (Get-Date).AddDays(-$Days)
Level = 1,2
} |
Select-Object -Property $MachineName, TimeCreated,
$FileName, $Name, $Version,
$TotalTime, $DegradationTime, Message |
Out-GridView

PowerShell 技能连载 - 寻找开始时间退化

http://blog.vichamp.com/2023/08/08/finding-start-time-degradation/

作者

吴波

发布于

2023-08-08

更新于

2024-03-29

许可协议

评论