-
Notifications
You must be signed in to change notification settings - Fork 3
/
Debug-Computer.ps1
227 lines (186 loc) · 8.21 KB
/
Debug-Computer.ps1
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
function Debug-Computer {
<#
.SYNOPSIS
Grabs event logs and other reports.
.DESCRIPTION
Grabs stability metrics,DumpSettings,cleanShutdowns,dirtyShutdowns, and Bluescreen events, Recent Error , groups the types of errors together
.PARAMETER StabilityThreshhold
Marks the stability threshhold at which you want to start search logs on
.PARAMETER StartTime
Start search logs this many days ago
.PARAMETER EndTime
End searching for logs on this date
.PARAMETER LowStability
Forces the search of logs by saying there is low stability
.INPUTS
None
.OUTPUTS
Description of objects that are output by the script.
.EXAMPLE
Debug-Computer
.EXAMPLE
Debug-Computer -StabilityThreshhold 4
.EXAMPLE
Debug-Computer -StabilityThreshhold 4 -StartTime -76
.EXAMPLE
Debug-Computer -StartTime -23 -LowStability
.EXAMPLE
Debug-Computer -StartTime -500 -EndTime -25 -LowStability
.EXAMPLE
Debug-Computer -StartTime -1 -EndTime 0 -LowStability
.LINK
https://devblogs.microsoft.com/scripting/use-powershell-to-determine-computer-reliability/
.NOTES
Detail on what the script does, if this is needed.
#>
[CmdletBinding(DefaultParameterSetName = 'Threshhold')]
param (
[Parameter(Mandatory = $false,Position = 0,ParameterSetName = "Threshhold")]
[int]$StabilityThreshhold = 7,
[Parameter(Mandatory = $false,Position = 1)]
[int]$StartTime = -14,
[Parameter(Mandatory = $false,Position = 2)]
$EndTime = (Get-Date),
[Parameter(Mandatory = $false,ParameterSetName = "Force")]
[switch]$LowStability
)
begin {
# Get Current Stability Metrics
$stabilityMetrics = (Get-Ciminstance -ClassName "Win32_ReliabilityStabilityMetrics" | Measure-Object -Average -Maximum -Minimum -Property systemStabilityIndex)
if ([double]($stabilityMetrics.Average) -gt $stabilityThreshhold ) {
$LowStability = $true
} else {
$currentMetrics = "Current Stability Index:($([math]::Round($stabilityMetrics.Average,2))/10)"
}
# Use this function to get what items are having trouble and how much counts
Function Get-SortedReliabilityRecords {
Param ([string]$computer = ".")
Get-CimInstance -ClassName "Win32_ReliabilityRecords" |
Group-Object -Property sourcename, eventidentifier -NoElement |
Sort-Object -Descending count | Select-Object -Property count, @{Label = "Source"; Expression = { $_.values[0] } },@{Label = "eventidentifier"; Expression = { $_.values[1] } } |
Format-Table -Wrap -AutoSize
}
function Get-DumpSettings {
param(
$regdata = (Get-ItemProperty -path "HKLM:\System\CurrentControlSet\Control\CrashControl")
)
$dumpsettings = @{}
$dumpsettings.CrashDumpMode = switch ($regdata.CrashDumpEnabled) {
1 { if ($regdata.FilterPages) { "Active Memory Dump" } else { "Complete Memory Dump" } }
2 {"Kernel Memory Dump"}
3 {"Small Memory Dump"}
7 {"Automatic Memory Dump"}
default {"Unknown"}
}
$dumpsettings.DumpFileLocation = $regdata.DumpFile
[bool]$dumpsettings.AutoReboot = $regdata.AutoReboot
[bool]$dumpsettings.OverwritePrevious = $regdata.Overwrite
[bool]$dumpsettings.AutoDeleteWhenLowSpace = -not $regdata.AlwaysKeepMemoryDump
[bool]$dumpsettings.SystemLogEvent = $regdata.LogEvent
return $dumpsettings
}
$eventValues = @{}
$eventKeywords = @(
"AuditFailure",
"AuditSuccess",
"CorrelationHint2",
"EventLogClassic",
"Sqm",
"WdiDiagnostic",
"WdiContext",
"ResponseTime",
"None"
)
foreach ($eventKeyword in $eventKeywords){
[string]$value = ([System.Diagnostics.Eventing.Reader.StandardEventKeywords]::$($eventKeyword)).value__
$eventValues.add("$eventKeyword",$value)
}
$Levels = @{
Verbose = 5
Informational = 4
Warning = 3
Error = 2
Critical = 1
LogAlways = 0
}
$cleanShutdowns = @{
LogName = 'System'
ProviderName ='EventLog'
#Path =<String[]>
Keywords = $eventValues['EventLogClassic']
ID = '6006'
Level = "$($Levels.Informational)"
StartTime = (Get-Date).AddDays($StartTime)
#EndTime =$EndTime
#UserID =<SID>
#Data =''
}
$dirtyShutdowns = @{
LogName = 'System'
ProviderName = 'EventLog'
#Path =<String[]>
Keywords = $eventValues['EventLogClassic']
ID = '6008'
Level = "$($Levels.Error)"
StartTime = (Get-Date).AddDays($StartTime)
#EndTime =$EndTime
#UserID =<SID>
#Data =''
}
$blueScreenEvents = @{
LogName = 'application'
ProviderName ='Windows Error*'
#Path =<String[]>
Keywords = $eventValues['EventLogClassic']
ID ='6008'
Level = "$($Levels.Error)"
StartTime = (Get-Date).AddDays($StartTime)
#EndTime =$EndTime
#UserID =<SID>
#Data =''
}
}
process {
if ($lowStability) {
[PSCustomObject]@{
StabilityMetrics = [math]::Round($stabilityMetrics.Average,2)
StabilityThreshhold = $stabilityThreshhold
} | Format-Table -AutoSize
Write-Output "Current Crash Logging Settings"
Get-DumpSettings
Get-SortedReliabilityRecords
# Group Application errors
$applicationError = Get-CimInstance -ClassName Win32_ReliabilityRecords -Filter "SourceName = 'application error'" |
Select-Object ProductName | Group-Object -Property productname -NoElement | Sort-Object count -Descending
# Get Time generated by top three
Write-output "Current 'Recent Error' data shows you the applications that have had errors recently"
foreach ($Program in $applicationError.name) {
$timegenerated = Get-CimInstance -ClassName Win32_ReliabilityRecords -Filter "SourceName = 'application error' AND ProductName = '$Program'" |
Select-Object timegenerated | Sort-Object name,timegenerated -Descending
foreach ($time in $timegenerated){
[PSCustomObject]@{
Application = $Program
TimeGenerated = $time.timegenerated
}
}
}
$events = @(
@{Name = "Blue Screen Events" ; Action = Invoke-Command { Get-WinEvent -FilterHashtable $blueScreenEvents -ea SilentlyContinue | Where-Object -Property Message -Match 'BlueScreen' | ft -auto -wrap} ; },
@{Name = "Dirty Shutdown Events" ; Action = Invoke-Command { Get-WinEvent -FilterHashtable $dirtyShutdowns -ea SilentlyContinue | Where-Object -Property Message -Match 'was unexpected'| ft -auto -wrap} ; },
@{Name = "Clean Shutdown Events" ; Action = Invoke-Command { Get-WinEvent -FilterHashtable $cleanShutdowns -ea SilentlyContinue | ft -auto -wrap} ; }
)
foreach ($event in $events){
if ($null -ne $event.action){
"------------------------------------"
""
Write-Output "Aggregating $($event.name)"
$event.action
}
}
}
}
end {
""
$currentMetrics
}
}