cheat-sheets

Windows Troubleshooting

A toolbox for diagnosing and repairing Windows: system file and image repair (sfc, DISM), disk checks, event log queries, services, performance counters and boot repair. Use an elevated PowerShell or Command Prompt (PowerShell Cheat-Sheet). Related: Windows Updates, Windows Networking, Group Policy, Active Directory.

Documentation: Windows commands, Repair a Windows image

System File and Image Repair #

Run in this order: DISM repairs the component store, then SFC repairs system files from it.

COMMANDDESCRIPTION
DISM /Online /Cleanup-Image /CheckHealthQuick check for a flagged corruption
DISM /Online /Cleanup-Image /ScanHealthDeeper scan (a few minutes)
DISM /Online /Cleanup-Image /RestoreHealthRepair the image (uses Windows Update as source)
DISM /Online /Cleanup-Image /RestoreHealth /Source:WIM:D:\sources\install.wim:1 /LimitAccessRepair from a mounted ISO instead of Windows Update (match the edition index)
sfc /scannowScan and repair protected system files
sfc /verifyonlyScan without repairing
sfc /scanfile=C:\Windows\System32\<FILE>Check one file
findstr /c:"[SR]" %windir%\Logs\CBS\CBS.log > "%userprofile%\Desktop\sfclogs.txt"Extract SFC entries from the CBS log
DISM /Online /Cleanup-Image /AnalyzeComponentStoreComponent store size and reclaimable space
DISM /Online /Cleanup-Image /StartComponentCleanupRemove superseded components (frees disk space)
Repair-WindowsImage -Online -RestoreHealthPowerShell equivalent of DISM RestoreHealth
Get-WindowsImage -ImagePath D:\sources\install.wimList editions and indexes in an ISO

If sfc reports corruption it cannot fix, run DISM /RestoreHealth and then sfc /scannow again. Logs: C:\Windows\Logs\CBS\CBS.log and C:\Windows\Logs\DISM\dism.log. Reset stuck updates in Windows Updates.

Disk Checks #

COMMANDDESCRIPTION
chkdskRead-only check of the current volume
chkdsk C: /fFix file system errors (schedules at reboot for the system drive)
chkdsk C: /rFind bad sectors and recover data (implies /f, slow)
chkdsk C: /scanOnline scan of an NTFS volume (no downtime)
chkdsk C: /spotfixOffline repair of only the issues found by /scan
Repair-Volume -DriveLetter C -ScanPowerShell online scan
Repair-Volume -DriveLetter C -OfflineScanAndFixPowerShell offline repair
Get-VolumeVolumes with size, free space and health
Get-Disk / Get-PhysicalDiskDisks and HealthStatus
Get-PhysicalDisk | Get-StorageReliabilityCounter | Select Temperature,Wear,ReadErrorsTotalSMART-like counters
wmic diskdrive get status,modelQuick SMART status (deprecated, still present on many builds)
fsutil dirty query C:Is the volume flagged dirty
fsutil volume diskfree C:Free space detail
defrag C: /OOptimise (TRIM on SSD, defrag on HDD)
Optimize-Volume -DriveLetter C -ReTrim -VerboseRun TRIM

Event Logs #

Get-WinEvent reads event logs and is much faster with -FilterHashtable than with Where-Object.

COMMANDDESCRIPTION
Get-WinEvent -ListLog *All logs (-ListLog * | Sort RecordCount -Desc)
Get-WinEvent -LogName System -MaxEvents 50Latest events
Get-WinEvent -FilterHashtable @{LogName='System'; Level=1,2}Critical (1) and Error (2)
Get-WinEvent -FilterHashtable @{LogName='System'; Level=2; StartTime=(Get-Date).AddHours(-24)}Errors in the last 24 hours
Get-WinEvent -FilterHashtable @{LogName='Application'; ProviderName='.NET Runtime'}By provider
Get-WinEvent -FilterHashtable @{LogName='Security'; Id=4625} -MaxEvents 20Failed logons (needs admin)
Get-WinEvent -FilterHashtable @{LogName='System'; Id=41,6008}Unexpected shutdowns
Get-WinEvent -FilterHashtable @{LogName='System'; Id=1074}Planned restart or shutdown (who and why)
Get-WinEvent -FilterHashtable @{LogName='Microsoft-Windows-WindowsUpdateClient/Operational'}Windows Update history
Get-WinEvent -ComputerName <PC> -LogName System -MaxEvents 20Remote machine
Get-WinEvent -Path C:\logs\saved.evtxRead an exported log
Get-WinEvent -FilterHashtable @{LogName='System'; Level=2} | Group-Object ProviderName | Sort Count -Desc | Select -First 10Noisiest error sources
wevtutil qe System /c:20 /rd:true /f:textClassic query: 20 newest, text format
wevtutil epl System C:\temp\system.evtxExport a log
wevtutil cl ApplicationClear a log (destroys evidence)
Get-EventLog -LogName System -Newest 20Old cmdlet (Windows PowerShell 5.1 only, classic logs)

Levels: 1 Critical, 2 Error, 3 Warning, 4 Information, 5 Verbose. Useful event IDs:

IDLOGMEANING
41SystemKernel-Power: restarted without a clean shutdown
6005 / 6006SystemEvent Log service started / stopped (boot and shutdown)
6008SystemPrevious shutdown was unexpected
1074SystemShutdown or restart initiated, with reason
7034 / 7036 / 7045SystemService crashed / changed state / installed
4624 / 4625SecuritySuccessful / failed logon
4740SecurityAccount locked out
1000 / 1002ApplicationApplication crash / hang
10016SystemDCOM permission warning (usually harmless)

Services #

COMMANDDESCRIPTION
Get-ServiceAll services
Get-Service -Name SpoolerOne service
Get-Service | Where Status -eq RunningRunning services
Get-Service | Where { $_.StartType -eq 'Automatic' -and $_.Status -ne 'Running' }Automatic services that are stopped
Start-Service Spooler / Stop-Service Spooler / Restart-Service SpoolerControl a service (-Force also stops dependents)
Set-Service -Name Spooler -StartupType DisabledStartup type: Automatic, AutomaticDelayedStart, Manual, Disabled
Get-Service Spooler -DependentServices / -RequiredServicesDependencies
Get-CimInstance Win32_Service -Filter "Name='Spooler'" | Select Name,State,StartMode,StartName,PathNameAccount, path and mode
sc.exe query SpoolerClassic query
sc.exe qc SpoolerShow the service configuration
sc.exe config Spooler start= autoSet startup (space after = is required)
sc.exe failure Spooler reset= 86400 actions= restart/5000/restart/5000/restart/5000Recovery actions
Get-Process -Name <NAME>Running processes
Stop-Process -Name <NAME> -Force / taskkill /IM <EXE> /FKill a process
Get-Process | Sort CPU -Desc | Select -First 10 Name,CPU,IdTop CPU users
Get-Process | Sort WS -Desc | Select -First 10 Name,@{n='MB';e={[int]($_.WS/1MB)}}Top memory users
tasklist /svcWhich services run inside each process
Get-CimInstance Win32_StartupCommand | Select Name,Command,LocationStartup programs
Get-ScheduledTask | Where State -ne DisabledActive scheduled tasks

Performance #

COMMANDDESCRIPTION
Get-Counter '\Processor(_Total)\% Processor Time'CPU usage right now
Get-Counter '\Memory\Available MBytes'Free memory
Get-Counter '\PhysicalDisk(_Total)\Avg. Disk Queue Length'Disk queue (sustained over 2 per spindle is a bottleneck)
Get-Counter '\Network Interface(*)\Bytes Total/sec'Network throughput
Get-Counter '\Processor(_Total)\% Processor Time' -SampleInterval 2 -MaxSamples 10Ten samples, two seconds apart
Get-Counter -ListSet * | Select CounterSetNameAvailable counter sets
Get-Counter -Counter '\Process(*)\% Processor Time' | Select -Expand CounterSamples | Sort CookedValue -Desc | Select -First 5Top processes by CPU
typeperf "\Processor(_Total)\% Processor Time" -sc 5Classic counter sampling
Get-CimInstance Win32_OperatingSystem | Select @{n='FreeMB';e={[int]($_.FreePhysicalMemory/1KB)}},@{n='TotalMB';e={[int]($_.TotalVisibleMemorySize/1KB)}}Memory summary
(Get-Date) - (Get-CimInstance Win32_OperatingSystem).LastBootUpTimeUptime
Get-ComputerInfo | Select OsName,OsVersion,CsProcessors,CsTotalPhysicalMemorySystem overview
perfmon / perfmon /rel / resmonPerformance Monitor, Reliability Monitor, Resource Monitor
logman create counter Baseline -c "\Processor(_Total)\% Processor Time" "\Memory\Available MBytes" -si 15 -o C:\PerfLogs\baselineStart a data collector for a baseline
logman start Baseline / logman stop BaselineControl it
taskmgrTask Manager

Memory and Crash Analysis #

COMMANDDESCRIPTION
mdsched.exeWindows Memory Diagnostic (reboots to test RAM)
Get-WinEvent -FilterHashtable @{LogName='System'; ProviderName='Microsoft-Windows-WER-SystemErrorReporting'}Bugcheck (blue screen) records
Get-ChildItem C:\Windows\MinidumpCrash dump files
Get-WmiObject Win32_PageFileUsagePage file use (or Get-CimInstance Win32_PageFileUsage)
msinfo32System information viewer
dxdiagDisplay and sound diagnostics
systeminfoOS, hotfixes, boot time and hardware summary
Get-HotFix | Sort InstalledOn -Desc | Select -First 10Recent updates (see Windows Updates)

Analyse dumps with WinDbg or WhoCrashed. For a bluescreen code lookup, note the stop code and the faulting driver from the dump.

Boot Repair #

Start from Windows installation media (boot, Repair your computer, Troubleshoot, Command Prompt) or Advanced Startup (shutdown /r /o /t 0). In WinRE the Windows drive letter may not be C:, so check with diskpart, list vol or dir.

COMMANDDESCRIPTION
bootrec /fixmbrWrite a new master boot record (BIOS/MBR systems)
bootrec /fixbootWrite a new boot sector (may say access denied on UEFI; use bcdboot instead)
bootrec /scanosLook for Windows installations
bootrec /rebuildbcdRebuild the Boot Configuration Data store
bcdboot C:\Windows /s S: /f UEFIRecreate boot files on the EFI System Partition (letter S: assigned with diskpart)
bcdedit /enum allShow boot entries
bcdedit /set {default} safeboot minimalNext boots go to Safe Mode (bcdedit /deletevalue {default} safeboot to undo)
bcdedit /set {default} bootmenupolicy legacyEnable the F8-style boot menu
diskpartPartition tool (list disk, sel disk 0, list vol, sel vol 2, assign letter=S)
sfc /scannow /offbootdir=C:\ /offwindir=C:\WindowsRepair system files from WinRE
DISM /Image:C:\ /Cleanup-Image /RestoreHealth /Source:D:\sources\install.wim:1Repair an offline image
DISM /Image:C:\ /Cleanup-Image /RevertPendingActionsRoll back a stuck pending update
chkdsk C: /fFix the file system from WinRE
msconfigChoose a diagnostic or safe boot, hide Microsoft services to find a culprit

EFI repair sequence (UEFI, GPT disk):

text
diskpart
 list disk
 sel disk 0
 list vol            (find the FAT32 volume of about 100-500 MB)
 sel vol 2
 assign letter=S
 exit
bcdboot C:\Windows /s S: /f UEFI

Other recovery: systemreset, Reset this PC, System Restore (rstrui.exe), wbadmin backups, and Safe Mode from Advanced Startup. BitLocker-encrypted drives need the recovery key before bootrec or chkdsk can access them (manage-bde -status, manage-bde -unlock D: -RecoveryPassword <KEY>).

Quick Triage Checklist #

  1. Get-WinEvent -FilterHashtable @{LogName='System'; Level=1,2; StartTime=(Get-Date).AddHours(-24)} for recent errors.
  2. Get-Service | Where { $_.StartType -eq 'Automatic' -and $_.Status -ne 'Running' } for failed services.
  3. Get-Volume for free space (a full system drive breaks many things).
  4. DISM /Online /Cleanup-Image /RestoreHealth then sfc /scannow.
  5. Get-Counter for CPU, memory and disk pressure; Get-Process for the culprit.
  6. Windows Networking for connectivity and DNS; Windows Updates for update problems.
  7. Check the Reliability Monitor (perfmon /rel) for a timeline of crashes and installs.

Not Verified #

Commands were written from the Microsoft documentation and not executed. Run repairs on a test machine first and keep a backup before chkdsk /r, bootrec or bcdedit changes.

Search all sheets

Tip: / or Ctrl/Cmd+K to open, Esc to close.