-
Notifications
You must be signed in to change notification settings - Fork 6
windows_dism_sfc_chkdsk_maintenance.ps1
Runs standard Windows health checks and repair commands for system maintenance.
This comprehensive maintenance script performs automated Windows system health checks and repairs using DISM, SFC, and chkdsk utilities. Designed for unattended execution in RMM environments, it supports selective operation execution and optional post-maintenance reboot.
Runs standard Windows health checks and repair commands including DISM image health scans, disk checks, system file verification, and component cleanup. Designed for unattended execution in RMM environments to perform routine system maintenance and repair operations.
- PowerShell 5.1 or later
- Administrator privileges required
- Windows 8.1/Server 2012 R2 or later for DISM commands
- Sufficient disk space for repair operations
All inputs are hardcoded in the script body:
Operation Run Flags:
-
$RunDismScan: Whether to run DISM ScanHealth to check for image corruption (default:$true) -
$RunDismRestore: Whether to run DISM RestoreHealth to repair image corruption (default:$true) -
$RunChkdsk: Whether to run chkdsk on local drives - requires reboot to complete (default:$false) -
$RunSfc: Whether to run System File Checker to verify and repair system files (default:$true) -
$RunDismCleanup: Whether to run DISM component cleanup to remove superseded components (default:$true)
Operation Parameters:
-
$ChkdskParameters: Parameters for chkdsk - use '/scan' for quick scan or '/f /r' for full check (default: '/scan')
Post-Operation Actions:
-
$RebootAfterMaintenance: Set to$trueto reboot the system after maintenance with a 5-minute warning (default:$false)
- All maintenance operations are optional via hardcoded input flags
- DISM operations use online mode against the running Windows installation
- chkdsk runs against all fixed local drives (DriveType = 3)
- Commands run synchronously with full output captured for logging
- Component cleanup includes retry logic with Windows Update service management
The script performs the following operations:
- Input Validation: Validates all hardcoded boolean flags and parameters
- DISM Scan Health (if enabled): Checks Windows image for corruption
- DISM Restore Health (if enabled): Repairs detected image corruption
- Disk Check (if enabled): Runs chkdsk on all fixed drives
- System File Check (if enabled): Verifies and repairs system files using SFC
-
Component Cleanup (if enabled): Removes superseded Windows components
- Stops Windows Update service to release locks
- Retries up to 2 times on access denied errors
- Restarts Windows Update service when complete
- Final Status: Reports operation counts and overall result
- Optional Reboot: Schedules system reboot with 5-minute warning if enabled
Each operation's success or failure is tracked individually. DISM log files are checked for access denied errors. Failed operations are reported but script continues to next operation.
- Hardcoded values (defined within the script body)
- System commands (DISM, chkdsk, sfc)
- Error
- No secrets are printed to the console
- Requires elevated permissions to modify system components
- Operations may cause system modifications and require reboots
- Windows Update service is temporarily stopped during component cleanup to prevent file locks
N/A (local system commands only)
- 0 = Success (all enabled operations completed)
- 1 = Failure (one or more operations failed)
[ INPUT VALIDATION ]
--------------------------------------------------------------
RunDismScan : True
RunDismRestore : True
RunChkdsk : False
RunSfc : True
RunDismCleanup : True
ChkdskParameters : /scan
RebootAfterMaintenance : False
[ DISM SCAN HEALTH ]
--------------------------------------------------------------
Starting DISM image scan...
Deployment Image Servicing and Management tool
Version: 10.0.19041.1
Image Version: 10.0.19041.1
[==========================100.0%==========================]
No component store corruption detected.
The operation completed successfully.
Result : Success
[ DISM RESTORE HEALTH ]
--------------------------------------------------------------
Starting DISM image repair...
Deployment Image Servicing and Management tool
Version: 10.0.19041.1
Image Version: 10.0.19041.1
[==========================100.0%==========================]
The restore operation completed successfully.
Result : Success
[ SYSTEM FILE CHECK ]
--------------------------------------------------------------
Starting system file verification...
Beginning system scan. This process will take some time.
Windows Resource Protection found corrupt files and successfully repaired them.
Result : Success
[ FINAL STATUS ]
--------------------------------------------------------------
Operations Run : 3
Operations Passed : 3
Operations Failed : 0
Overall Result : Success
[ SCRIPT COMPLETED ]
--------------------------------------------------------------
[ FINAL STATUS ]
--------------------------------------------------------------
Operations Run : 3
Operations Passed : 3
Operations Failed : 0
Overall Result : Success
[ SCRIPT COMPLETED ]
--------------------------------------------------------------
[ REBOOT SCHEDULE ]
--------------------------------------------------------------
Scheduling system reboot in 5 minutes...
Please save any open work.
Reboot command issued.
- v1.0.3 (2025-10-31) - Added full command output display for all operations (DISM and SFC) to improve transparency and troubleshooting capabilities
- v1.0.2 (2025-10-31) - Fixed DISM component cleanup access denied errors by stopping Windows Update service and adding retry logic with improved diagnostics
- v1.0.1 (2025-10-31) - Added optional reboot functionality with 5-minute warning after maintenance
- v1.0.0 (2025-10-31) - Initial Style A compliant release with Windows maintenance operations for RMM environments
- View Script Source
- Scripts - Back to script index