Skip to content

Add Windows BSOD troubleshooting script#5

Open
benhunter wants to merge 6 commits intomasterfrom
troubleshoot-bsod
Open

Add Windows BSOD troubleshooting script#5
benhunter wants to merge 6 commits intomasterfrom
troubleshoot-bsod

Conversation

@benhunter
Copy link
Copy Markdown
Owner

Add windows/troubleshoot-bsod.ps1 — a PowerShell tool to collect system info, recent bugcheck and kernel-power events, disk/volume and storage reliability counters, BitLocker status, filesystem scans, SFC/DISM, installed drivers, and crash dump inventory; supports optional chkdsk/sfc/dism runs and event log export, and produces a heuristic summary and recommended next steps. Also update README.md to reference the new Windows troubleshooting script.

Add windows/troubleshoot-bsod.ps1 — a PowerShell tool to collect system info, recent bugcheck and kernel-power events, disk/volume and storage reliability counters, BitLocker status, filesystem scans, SFC/DISM, installed drivers, and crash dump inventory; supports optional chkdsk/sfc/dism runs and event log export, and produces a heuristic summary and recommended next steps. Also update README.md to reference the new Windows troubleshooting script.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Windows-focused PowerShell script to gather crash/storage diagnostics and optionally run common repair actions, and documents it in the root README for discoverability.

Changes:

  • Added windows/troubleshoot-bsod.ps1 to collect system info, relevant event logs, storage health counters, driver inventory, and crash dump inventory.
  • Added optional actions for exporting event logs and running CHKDSK/SFC/DISM, plus a heuristic summary and recommended next steps.
  • Updated README.md to reference the new Windows troubleshooting script.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 9 comments.

File Description
windows/troubleshoot-bsod.ps1 New end-to-end BSOD/storage data collection + optional repair script with summary output.
README.md Adds a Windows section referencing the troubleshooting script.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread windows/troubleshoot-bsod.ps1 Outdated
Comment thread windows/troubleshoot-bsod.ps1 Outdated
Comment on lines +421 to +423
$minidumpPath = "C:\Windows\Minidump"
$memoryDmpPath = "C:\Windows\MEMORY.DMP"

Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crash dump paths are hard-coded to C:\Windows\.... On systems where %WINDIR% isn’t on C:, the script won’t find dumps. Use $env:windir/$env:SystemRoot to build these paths.

Copilot uses AI. Check for mistakes.
Comment on lines +531 to +542
$summaryFindings.Add("BugCheck events in last $DaysBack days: $bugcheckCount")
$summaryFindings.Add("Kernel-Power 41 events in last $DaysBack days: $kernelPowerCount")
$summaryFindings.Add("Disk / NTFS / storage-related events in last $DaysBack days: $diskEventCount")

if (Test-Path $minidumpPath) {
$dumpCount = (Get-ChildItem $minidumpPath -File | Measure-Object).Count
$summaryFindings.Add("Minidump files present: $dumpCount")
}

if ($summaryFindings.Count -eq 0) {
$summaryFindings.Add("No obvious storage-health indicators were detected by the script. Review event logs, dump files, and repair output manually.")
}
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$summaryFindings.Count -eq 0 can never be true here because you always add at least three lines (BugCheck/Kernel-Power/Disk event counts) before this check. If you intended to emit the “no obvious indicators” message only when there are no concerns, consider tracking concerns in a separate list and always appending the baseline counts separately.

Copilot uses AI. Check for mistakes.
Comment on lines +117 to +127
try {
Write-Info "Collecting: $Title"
$obj = & $ScriptBlock
$text = $obj | Format-Table -AutoSize | Out-String -Width 4096
Save-Text -Path $Path -Text $text
}
catch {
$err = "Failed to collect [$Title]: $($_.Exception.Message)"
Write-Warning $err
Save-Text -Path $Path -Text $err
}
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Save-ObjectAsTable/Save-ObjectAsList rely on try/catch, but errors from many cmdlets inside the scriptblock are non-terminating and won’t be caught, which can result in empty/partial output files without the “Failed to collect …” text. Consider forcing terminating behavior (e.g., set $ErrorActionPreference='Stop' within the helper while executing the scriptblock) so collection failures are reliably captured.

Copilot uses AI. Check for mistakes.
Comment thread README.md Outdated

function Safe-Get {
param([scriptblock]$ScriptBlock)
try { & $ScriptBlock } catch { $null }
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Safe-Get won’t suppress many failures because most cmdlet errors are non-terminating by default (so catch won’t run). If the intent is “return $null on any error”, consider invoking the scriptblock with $ErrorActionPreference='Stop' (or setting -ErrorAction Stop on the cmdlets inside) so exceptions are actually caught.

Suggested change
try { & $ScriptBlock } catch { $null }
try {
& {
$ErrorActionPreference = 'Stop'
& $ScriptBlock
}
}
catch {
$null
}

Copilot uses AI. Check for mistakes.
# ---------------------------
Write-Section "Drivers and Devices"

Save-CommandOutput -Title "Installed drivers" -Path (Join-Path $driversDir "driverquery.txt") -ScriptBlock {
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

driverquery /v /fo csv produces CSV output, but it’s being saved to driverquery.txt. Consider using a .csv filename so the output is immediately usable in Excel/PowerShell imports.

Suggested change
Save-CommandOutput -Title "Installed drivers" -Path (Join-Path $driversDir "driverquery.txt") -ScriptBlock {
Save-CommandOutput -Title "Installed drivers" -Path (Join-Path $driversDir "driverquery.csv") -ScriptBlock {

Copilot uses AI. Check for mistakes.
Comment thread windows/troubleshoot-bsod.ps1 Outdated
Comment on lines +517 to +529
$bugcheckCount = (Safe-Get {
(Get-WinEvent -FilterHashtable @{ LogName='System'; Id=1001; StartTime=$startTime } | Measure-Object).Count
}) ?? 0

$kernelPowerCount = (Safe-Get {
(Get-WinEvent -FilterHashtable @{ LogName='System'; Id=41; StartTime=$startTime } | Measure-Object).Count
}) ?? 0

$diskEventCount = (Safe-Get {
(Get-WinEvent -FilterHashtable @{ LogName='System'; StartTime=$startTime } |
Where-Object { $_.ProviderName -match 'disk|storahci|stornvme|Ntfs|volmgr|volsnap' } |
Measure-Object).Count
}) ?? 0
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script uses the null-coalescing operator (??) for event counts, which is PowerShell 7+ syntax and will fail to parse/run in Windows PowerShell 5.1 (still common on Windows 11 unless the user explicitly uses pwsh). Either replace ?? with PS5.1-compatible null handling, or add a #requires -Version 7.0 (and update the header/README) to make the dependency explicit.

Suggested change
$bugcheckCount = (Safe-Get {
(Get-WinEvent -FilterHashtable @{ LogName='System'; Id=1001; StartTime=$startTime } | Measure-Object).Count
}) ?? 0
$kernelPowerCount = (Safe-Get {
(Get-WinEvent -FilterHashtable @{ LogName='System'; Id=41; StartTime=$startTime } | Measure-Object).Count
}) ?? 0
$diskEventCount = (Safe-Get {
(Get-WinEvent -FilterHashtable @{ LogName='System'; StartTime=$startTime } |
Where-Object { $_.ProviderName -match 'disk|storahci|stornvme|Ntfs|volmgr|volsnap' } |
Measure-Object).Count
}) ?? 0
$bugcheckCountResult = Safe-Get {
(Get-WinEvent -FilterHashtable @{ LogName='System'; Id=1001; StartTime=$startTime } | Measure-Object).Count
}
$bugcheckCount = if ($null -ne $bugcheckCountResult) { $bugcheckCountResult } else { 0 }
$kernelPowerCountResult = Safe-Get {
(Get-WinEvent -FilterHashtable @{ LogName='System'; Id=41; StartTime=$startTime } | Measure-Object).Count
}
$kernelPowerCount = if ($null -ne $kernelPowerCountResult) { $kernelPowerCountResult } else { 0 }
$diskEventCountResult = Safe-Get {
(Get-WinEvent -FilterHashtable @{ LogName='System'; StartTime=$startTime } |
Where-Object { $_.ProviderName -match 'disk|storahci|stornvme|Ntfs|volmgr|volsnap' } |
Measure-Object).Count
}
$diskEventCount = if ($null -ne $diskEventCountResult) { $diskEventCountResult } else { 0 }

Copilot uses AI. Check for mistakes.
benhunter and others added 3 commits April 13, 2026 22:01
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@benhunter
Copy link
Copy Markdown
Owner Author

@copilot would you take a look at this error that was in events/key_events.txt after I ran the script?

Copy link
Copy Markdown

Copilot AI commented Apr 14, 2026

@copilot would you take a look at this error that was in events/key_events.txt after I ran the script?

I pushed a fix in 40f6779 to make events/key_events.txt resilient when an event record’s Message can’t be rendered (common source of errors in that file). Please rerun the script and check events/key_events.txt again—if you still see an error, paste the exact line and I’ll narrow it down further.

….ps1)

Apply consistent formatting and readability fixes across troubleshoot-bsod.ps1: group complex Where-Object conditions with parentheses, move and format catch blocks, align and reflow Select-Object property lists and pipeline indentation, and normalize whitespace in hashtables and cmdlet arguments. These are stylistic changes only and should not alter script behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants