Skip to content
Menu

Windows Corrupted or SFC Fails - DISM Then SFC Repair

Runs DISM and SFC in the right order: checks the component store and system files, repairs damage in Auto mode, then checks again. Scan mode only reports.

Windows corrupted or SFC fails - DISM then SFC repair is free for members.

Enter your email to create your free account and get the file.

We'll email you the script and the weekly MSP Outpost email. Unsubscribe anytime. Privacy policy.

Already a member? Sign in.

Be the first to review Windows corrupted or SFC fails - DISM then SFC repair. Tell other MSPs how it worked for you.

Write a Review

LanguagePowerShell
Runs onWindows 10, Windows 11, Windows Server 2016+; runs as SYSTEM
NeedsPowerShell 5.1, administrator rights, internet or a Source for DISM
Changes thingsChanges what it runs on

What It Does

In Auto mode the script checks first and repairs what it finds damaged. DISM ScanHealth reads whether the component store is healthy, repairable or beyond repair, and sfc /verifyonly checks the protected system files. Both only read.

When the store is damaged, DISM RestoreHealth repairs it from Windows Update, or from the matching Windows image or folder you give it in Source. LimitAccess stops it contacting Windows Update. When system files are damaged, or the store was just repaired, it runs sfc /scannow. Run a fresh scan after repair to verify the outcome.

Mode Scan only checks and reports any damage as an error so the RMM flags it. Mode Repair runs both repairs even when the checks look clean. Results come from the DISM health state, SFC's own output and the repair lines in the CBS log. It never restarts the machine; when files will be replaced at the next boot, the answer says so.

Before You Run It

  • Budget at least 60 minutes in your RMM and allow longer when the maintenance window permits. Each SFC call has a 60-minute limit. The script sets no DISM timeout.
  • Check the target build, patch level, architecture, edition and installed languages against your repair source. Make sure SYSTEM can read it.
  • Run Mode Scan first on a machine you are unsure about, and read the result before repairing.
  • Make sure the machine can reach Windows Update, or give it a Source, before you run a repair.

When to Use DISM and SFC

Start with Mode=Scan on one bootable Windows endpoint when an update repeatedly fails with a servicing error, a built-in Windows component stops working, or SFC reports protected files it cannot fix. Record the failing KB or action and the error before you run the script. If several clients report the same failure after the same update, check the deployment and update policy before starting a repair across the fleet.

DISM ScanHealth inspects the Windows component store. SFC /verifyonly checks the installed protected system files. If the store is healthy and SFC finds damage, Auto attempts just SFC /scannow. If the store is repairable, Auto restores the store with DISM before attempting SFC so it has healthy replacement files. Use Repair only when you deliberately want both repair steps even if the initial checks are clean.

Stop when both scans are clean and investigate the original update, app, driver or policy. If DISM reports NonRepairable, hold the job and plan recovery with the client. Auto treats that state as damage and can still attempt a repair. If Windows will not boot or the disk is reporting read errors, use your recovery or storage triage process first. This script targets the running Windows installation.

Worked Ticket: A Windows Update Fails on One PC

Example ticket HD-2741. A Windows 11 Pro reception PC keeps failing the same cumulative update after an approved restart. The RMM runs as SYSTEM in Windows PowerShell 5.1. With Mode=Scan and OutputFormat=Text, the example checks return Component store: Repairable and System files: Corrupt. The run exits 2 and the final line is:

RESULT: ERROR | Error: Corruption found (component store Repairable; SFC corrupt system files) and Mode is Scan, so nothing was repaired. Run again with Mode Auto.

The client blocks direct Windows Update as a repair source. During the maintenance window, the technician stages an approved matching image locally, verifies the correct edition index, and chooses Mode=Auto, Source=wim:D:\sources\install.wim:6 and LimitAccess=true. Index 6 is an example. With DryRun=true, the Component store and System files rows show Would change. That preview tests the repair decision. DISM has yet to open the image or prove that it contains the needed files. After confirming the source and timing, run the same job with DryRun=false.

When Repair Data Is Missing or Unclear

If RestoreHealth fails with 0x800f081f, capture the full RMM error and the matching timestamps in %windir%\Logs\DISM\dism.log and %windir%\Logs\CBS\CBS.log. The job stops before SFC repair. Confirm the image path and index under SYSTEM, match the intended Windows release, architecture, edition and languages, and check that the source has the servicing level the target needs. LimitAccess=true blocks the Windows Update fallback. If policy allows Windows Update, check servicing policy and endpoint connectivity before retrying. Retry after correcting the source or access.

If SFC cannot give a verdict, record the run as inconclusive. This version uses DISM’s health state, English SFC output patterns and CBS [SR] entries. Localized output or missing log lines can leave SFC unclassified. Check the console output and CBS entries for that run rather than counting exit 0 from sfc.exe as a clean scan. A pending restart can also yield SKIPPED with script exit 0. Arrange the restart and run Scan again.

Verify the Repair and the Original Symptom

Keep the RMM result and the Item, Change and Result rows. A Done row records a completed command step. CHANGED records the repair path taken. To close the example ticket, run Mode=Scan again after any required restart and confirm DISM reports Healthy, SFC reports Clean and the script returns OK. Then retry the original KB and confirm it appears as successfully installed in Update history.

If you still see corruption, collect the time-matched CBS [SR] entries, DISM error and exact Windows build for escalation. If both checks pass and the KB still fails, take the update error to Windows Update troubleshooting. Avoid repeating the same repair job without new evidence.

Microsoft References

Repair a Windows image with DISM

Choose and configure a Windows repair source

Run System File Checker and interpret the results

Type and Risk

  • Type: Action. It makes its change, checks the change worked and says what changed. It exits 0, or 2 when it could not do the job.
  • Risk: Low. Set DryRun=true, or run it with -WhatIf, to list every change without making any.
  • What it changes: Repairs the Windows component store (DISM) and replaces corrupt protected system files (SFC).
  • Restart: It never restarts the machine itself. When a restart is needed to finish, the answer says so.
  • Typical run: 10 to 40 minutes.
  • Example answer: "Repaired: DISM restored the component store; SFC fixed 3 files"
  • Tested before listing on Windows 11 with Windows PowerShell 5.1, run as SYSTEM, against its own test cases.

Inputs

Pass an input as an argument (-Name value), as an environment variable with the same name, which is how most RMMs pass script variables, or change its default in the param() block at the top of the script. An argument wins over an environment variable, which wins over the default.

  • Mode: Auto (check, then repair what is damaged), Scan (check only) or Repair (always run RestoreHealth and sfc /scannow). Default Auto.
  • Source: Optional repair source for DISM, for example wim:D:\sources\install.wim:1 or esd:D:\sources\install.esd:1 (image index after the last colon). Must match the installed Windows build. Default empty (use Windows Update).
  • LimitAccess: true to stop DISM using Windows Update (use with Source). Default false.

Every script also takes DryRun, OutputFormat (Text, Answer, Json or Csv), ExportPath and ResultField, which writes the answer to an RMM custom field.

License

Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.

The Script

repair-windows-image.ps1 · 964 lines · 50.1 KB

Free for Members

Create a free account or sign in to read, copy and download this script.

Welcome Back

Sign in to your MSP Outpost account.