# Run DISM and SFC for System Repair

This PowerShell script performs a two-step process to repair system integrity issues on Windows. It first runs the **DISM** tool to restore the system image and then executes **SFC** to scan and repair system files, only if DISM completes successfully.

#### ⚙️ Features

- Automates the standard **DISM + SFC** repair sequence
- Color-coded console messages for success or failure
- Check DISM completion before running SFC to avoid redundant operations

##### 💻 Script

```powershell
# Run DISM to repair the system image
Write-Host "Running DISM repair..." -ForegroundColor Green
dism /online /cleanup-image /restorehealth

# Check if DISM was successful before running SFC
if ($?) {
    Write-Host "DISM completed successfully. Running SFC..." -ForegroundColor Green
    # Run SFC to scan and repair system files
    sfc /scannow
} else {
    Write-Host "DISM failed. Please check the DISM logs for errors." -ForegroundColor Red
}
```

#### 📝 Notes

- Requires **Administrator privileges**
- Best used when:
    
    
    - Windows features aren't working correctly
    - Updates fail repeatedly
    - System file corruption is suspected
- Log files:
    
    
    - DISM: `%windir%\Logs\DISM\dism.log`
    - SFC: `%windir%\Logs\CBS\CBS.log`

Suitable for ad‑hoc remediation or targeted deployments.

- Recommended for systems with suspected component store corruption, repeated update failures, or unexplained instability.​
- Because these operations can be lengthy and resource‑intensive, schedule deployments during maintenance windows where possible and monitor Tanium results for completion and error codes.​

##### **Alternative Method**

Create a Tanium package and enter the following in the command field. This method does not require uploading a script.

```powershell
cmd /c ..\..\Tools\StdUtils\TPowershell.exe -ExecutionPolicy Bypass -Command "DISM /ONLINE /CLEANUP-IMAGE /SCANHEALTH;DISM /ONLINE /CLEANUP-IMAGE /CHECKHEALTH;DISM.exe /Online /Cleanup-image /Restorehealth;dism.exe /Online /Cleanup-Image /StartComponentCleanup;sfc /scannow"

```

TPowershell.exe runs a PowerShell context that sequentially executes DISM /ScanHealth, /CheckHealth, /RestoreHealth, /StartComponentCleanup, and then sfc /scannow, in a single remediation action.