forked from fleschutz/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enable-crash-dumps.ps1
executable file
·297 lines (283 loc) · 10.3 KB
/
enable-crash-dumps.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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<#
.SYNOPSIS
Enables the writing of crash dumps
.DESCRIPTION
This PowerShell script enables the writing of crash dumps.
.EXAMPLE
PS> ./enable-crash-dumps
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
##################################################################
# #
# Written by: Ryan Waters #
# #
# Program: Get-Dump.ps1 #
# Date: 2-06-2020 #
# Purpose: To set registry keys to gather a WER Usermode Dump #
# and be able to change from a custom, mini, or FULL #
# Dumps for ease of use for customers and others. #
# #
# EULA: Code is free to use for all, and free to distribute #
# I just ask that you leave the credit information and #
# this EULA and Comment Section in tact and do not delete. #
# #
# Bitwise Values: (For reference) #
# #
# 0x00000000 - MiniDumpNormal #
# 0x00000001 - MiniDumpWithDataSegs #
# 0x00000002 - MiniDumpWithFullMemory #
# 0x00000004 - MiniDumpWithHandleData #
# 0x00000008 - MiniDumpFilterMemory #
# 0x00000010 - MiniDumpScanMemory #
# 0x00000020 - MiniDumpWithUnloadedModules #
# 0x00000040 - MiniDumpWithIndirectlyReferenced #
# 0x00000080 - MemoryMiniDumpFilterModulePaths #
# 0x00000100 - MiniDumpWithProcessThreadData #
# 0x00000200 - MiniDumpWithPrivateReadWriteMemory #
# 0x00000400 - MiniDumpWithoutOptionalData #
# 0x00000800 - MiniDumpWithFullMemoryInfo #
# 0x00001000 - MiniDumpWithThreadInfo #
# 0x00002000 - MiniDumpWithCodeSegs #
# 0x00004000 - MiniDumpWithoutAuxiliaryState #
# 0x00008000 - MiniDumpWithFullAuxiliaryState #
# 0x00010000 - MiniDumpWithPrivateWriteCopyMemory #
# 0x00020000 - MiniDumpIgnoreInaccessibleMemory #
# 0x00040000 - MiniDumpWithTokenInformation #
# #
##################################################################
#Setting Values:
$MDN = '0'
$MDWDS = '1'
$MDWFM = '2'
$MDWHD = '4'
$MDFM = '8'
$MDSM = '10'
$MDWUM = '20'
$MDWIR = '40'
$MMDFMP = '80'
$MDWPTD = '100'
$MDWPRWM = '200'
$MDWOD = '400'
$MDWFMI = '800'
$MDWTI = '1000'
$MDWCS = '2000'
$MDWAS = '4000'
$MDWFAS = '8000'
$MDWPWCM = '10000'
$MDIIM = '20000'
$MDWTOI = '40000'
$a = $MDN
$b = $MDWDS
$c = $MDWFM
$d = $MDWHD
$e = $MDFM
$f = $MDSM
$g = $MDWUM
$h = $MDWIR
$i = $MMDFMP
$j = $MDWPTD
$k = $MDWPRWM
$l = $MDWOD
$m = $MDWFMI
$n = $MDWTI
$o = $MDWCS
$p = $MDWAS
$q = $MDWFAS
$r = $MDWPWCM
$s = $MDIIM
$t = $MDWTOI
$0x = "0x"
$array = @()
Clear-Host
Write-Host "Setting up your machine to receive Usermode Dumps via WER."
Start-Sleep -seconds 3
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" -Name "DumpFolder" -Value "%LOCALAPPDATA%\CrashDumps" -PropertyType ExpandString -Force
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" -Name "DumpCount" -Value "10" -PropertyType DWORD -Force
clear-host
write-host "What would you like to do?"
write-host "(0) Disable Dumps and restore system to factory."
write-host "(1) Enable System for Full Dumps."
write-host "(2) Enable System for Mini Dumps."
write-host "(3) Enable System for custom dump with options."
$NCD = Read-Host "Enter a number option"
If ($NCD -eq '3')
{
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" -Name "DumpType" -Value "0" -PropertyType DWORD -Force
Do
{
clear-host
write-host "Here are the optional custom dump to add to your custom dump parameters:"
write-host "(1) Mini Dump Normal"
write-host "(2) Mini Dump With Data Segs"
write-host "(3) Mini Dump With Full Memory"
write-host "(4) Mini Dump With Handle Data"
write-host "(5) Mini Dump Filter Memory"
write-host "(6) Mini Dump Scan Memory"
write-host "(7) Mini Dump With Unloaded Modules"
write-host "(8) Mini Dump With Indirectly Referenced"
write-host "(9) Memory Mini Dump Filter Module Paths"
write-host "(10) Mini Dump With Process Thread Data"
write-host "(11) Mini Dump With Private Read Write Memory"
write-host "(12) Mini Dump Without Optional Data"
write-host "(13) Mini Dump With Full Memory Info"
write-host "(14) Mini Dump With Thread Info"
write-host "(15) Mini Dump With Code Segs"
write-host "(16) Mini Dump Without Auxiliary State"
write-host "(17) Mini Dump With Full Auxiliary State"
write-host "(18) Mini Dump With Private Write Copy Memory"
write-host "(19) Mini Dump Ignore Inaccessible Memory"
write-host "(20) Mini Dump With Token Information"
$Option = Read-Host "Enter one number value at a time and press enter. (Press 'q' when finished)"
if($Option -eq '1')
{
$array += [int]$a
}
ElseIf($Option -eq '2')
{
$array += [int]$b
}
ElseIf($Option -eq '3')
{
$array += [int]$c
}
ElseIf($Option -eq '4')
{
$array += [int]$d
}
ElseIf($Option -eq '5')
{
$array += [int]$e
}
ElseIf($Option -eq '6')
{
$array += [int]$f
}
ElseIf($Option -eq '7')
{
$array += [int]$g
}
ElseIf($Option -eq '8')
{
$array += [int]$h
}
ElseIf($Option -eq '9')
{
$array += [int]$i
}
ElseIf($Option -eq '10')
{
$array += [int]$j
}
ElseIf($Option -eq '11')
{
$array += [int]$k
}
ElseIf($Option -eq '12')
{
$array += [int]$l
}
ElseIf($Option -eq '13')
{
$array += [int]$m
}
ElseIf($Option -eq '14')
{
$array += [int]$n
}
ElseIf($Option -eq '15')
{
$array += [int]$o
}
ElseIf($Option -eq '16')
{
$array += [int]$p
}
ElseIf($Option -eq '17')
{
$array += [int]$q
}
ElseIf($Option -eq '18')
{
$array += [int]$r
}
ElseIf($Option -eq '19')
{
$array += [int]$s
}
ElseIf($Option -eq '20')
{
$array += [int]$t
}
ElseIf($Option -eq 'q')
{
write-host "Closing application."
Start-Sleep -seconds 2
}
Else
{
write-host "Invalid Option, Try again."
Start-Sleep -seconds 2
}
}
While($Option -ne "q")
$sum = $array -join '+'
$SumArray = Invoke-Expression $sum
$FinalSum = $0x + $SumArray
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" -Name "CustomDumpFlags" -Value "$FinalSum" -PropertyType DWORD -Force
write-host " "
write-host "Setting up the system for crash dumps requires a reboot"
}
ElseIf ($NCD -eq '0')
{
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" -Name "DumpCount" -Force -ErrorAction SilentlyContinue
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" -Name "DumpType" -Force -ErrorAction SilentlyContinue
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" -Name "DumpFolder" -Force -ErrorAction SilentlyContinue
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" -Name "CustomDumpFlags" -Force -ErrorAction SilentlyContinue
write-host " "
$reboot = read-host "Registry reset to factory settings and cleared. It is recommended to restart your machine, would you like to now?"
if($reboot -eq "Yes" -or $reboot -eq "Y" -or $reboot -eq "yes" -or $reboot -eq "y")
{
shutdown -r
}
Else
{
write-host "Please restart the machine for settings to take effect at your convenience."
}
}
ElseIf ($NCD -eq '1')
{
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" -Name "DumpType" -Value "2" -PropertyType DWORD -Force
write-host "The computer has been set up to create a Full Sized Dump and will be located in %LOCALAPPDATA%\CrashDumps."
write-host "The computer must also restart for settings to take effect. Would you like to now? (Y/n)"
if($reboot -eq "Yes" -or $reboot -eq "Y" -or $reboot -eq "yes" -or $reboot -eq "y")
{
shutdown -r
}
Else
{
write-host "Please restart the machine for settings to take effect at your convenience."
}
}
ElseIf ($NCD -eq '2')
{
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" -Name "DumpType" -Value "1" -PropertyType DWORD -Force
write-host "The computer has been set up to create a Mini Dump and will be located in %LOCALAPPDATA%\CrashDumps."
write-host "The computer must also restart for settings to take effect. Would you like to now? (Y/n)"
if($reboot -eq "Yes" -or $reboot -eq "Y" -or $reboot -eq "yes" -or $reboot -eq "y")
{
shutdown -r
}
Else
{
write-host "Please restart the machine for settings to take effect at your convenience."
}
}
Else
{
Write-Host "You did not enter a valid option. Please re-run Get-Dump.ps1"
Start-Sleep -seconds 5
}
exit 0 # success