Runs DISM RestoreHealth first and SFC afterwards, which is the order that works: SFC repairs from the component store, so repairing the store first is what makes the scan succeed. Both outputs are parsed down to one line each, including the case where SFC found corruption it could not fix and you need CBS.log. Allow 15 minutes or more.
powershell
# Repair System Files (SFC + DISM)
# Single use case: verify and repair OS integrity (can take 15+ minutes)
#-----------------------------------------------------------------
function Write-Log {
param($Message)
Write-Host "<WRITE-LOG = `"*$Message*`">"
}
Write-Log "Running DISM RestoreHealth (this can take a while)..."
$dism = & dism.exe /Online /Cleanup-Image /RestoreHealth /NoRestart 2>&1
$dismResult = ($dism | Select-String "The operation completed successfully|The restore operation completed" | Select-Object -First 1)
if ($dismResult) {
Write-Log "DISM: component store repaired/verified successfully."
} else {
$err = ($dism | Select-String "Error" | Select-Object -First 1)
Write-Log "DISM finished with issues: $(if ($err) { $err.ToString().Trim() } else { 'see CBS.log' })"
}
Write-Log "Running SFC /scannow..."
$sfc = & sfc.exe /scannow 2>&1
$sfcText = ($sfc -join " ") -replace "\x00", "" # sfc output is UTF-16 mangled when piped
if ($sfcText -match "did not find any integrity violations") {
Write-Log "SFC: no integrity violations found."
} elseif ($sfcText -match "successfully repaired") {
Write-Log "SFC: corrupt files found and repaired (details in CBS.log)."
} elseif ($sfcText -match "unable to fix") {
Write-Log "WARNING: SFC found corrupt files it could NOT fix - check $env:SystemRoot\Logs\CBS\CBS.log"
} else {
Write-Log "SFC finished - could not parse result, check CBS.log."
}
Write-Log "System file repair sequence complete."Run it across your fleet
This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.
More in Self-Healing & Repair
Clear the Windows Update Cache with PowerShell
2026-08-17Automate Disk Cleanup with PowerShell
2026-08-17Remove Windows Bloatware Apps with PowerShell
2026-08-17Flush the DNS Cache with PowerShell
2026-08-17Clear a Stuck Print Queue with PowerShell
2026-08-17Delete Old Temp Files with PowerShell
2026-08-17Ready when you are.
Try ServerEngine free for 7 days.