Conversation
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.
There was a problem hiding this comment.
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.ps1to 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.mdto 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.
| $minidumpPath = "C:\Windows\Minidump" | ||
| $memoryDmpPath = "C:\Windows\MEMORY.DMP" | ||
|
|
There was a problem hiding this comment.
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.
| $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.") | ||
| } |
There was a problem hiding this comment.
$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.
| 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 | ||
| } |
There was a problem hiding this comment.
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.
|
|
||
| function Safe-Get { | ||
| param([scriptblock]$ScriptBlock) | ||
| try { & $ScriptBlock } catch { $null } |
There was a problem hiding this comment.
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.
| try { & $ScriptBlock } catch { $null } | |
| try { | |
| & { | |
| $ErrorActionPreference = 'Stop' | |
| & $ScriptBlock | |
| } | |
| } | |
| catch { | |
| $null | |
| } |
| # --------------------------- | ||
| Write-Section "Drivers and Devices" | ||
|
|
||
| Save-CommandOutput -Title "Installed drivers" -Path (Join-Path $driversDir "driverquery.txt") -ScriptBlock { |
There was a problem hiding this comment.
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.
| Save-CommandOutput -Title "Installed drivers" -Path (Join-Path $driversDir "driverquery.txt") -ScriptBlock { | |
| Save-CommandOutput -Title "Installed drivers" -Path (Join-Path $driversDir "driverquery.csv") -ScriptBlock { |
| $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 |
There was a problem hiding this comment.
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.
| $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 } |
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>
|
@copilot would you take a look at this error that was in events/key_events.txt after I ran the script? |
Agent-Logs-Url: https://github.com/benhunter/scripts/sessions/80b7febd-e5ad-4787-ba1f-60c4ca4694ea Co-authored-by: benhunter <1780269+benhunter@users.noreply.github.com>
I pushed a fix in |
….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.
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.