-
Notifications
You must be signed in to change notification settings - Fork 0
Scripts Windows Maintenance
All scripts in Scripts/Windows/Maintenance/. All require administrator privileges.
What it does: One-command full system maintenance run.
Steps in order:
- Verifies administrator privileges (exits if not admin — does not auto-elevate).
- Installs Chocolatey if it is not already installed.
- Launches SFC (
sfc /scannow) and DISM (dism /Online /Cleanup-Image /RestoreHealth) as background processes so they run in parallel. - Saves a Chocolatey package inventory to
~/Documents/Chocolatey.txt(choco list --local-only). - Upgrades all Chocolatey packages (
choco upgrade all -y). - Upgrades pip if pip is on the PATH.
- Queries Windows Update for available updates and installs them. Does not force a reboot — it reports whether a reboot may be required.
Parameters: None.
Requirements: Administrator privileges. Chocolatey is installed automatically if missing; pip and Windows Update COM objects must be accessible.
Usage:
.\Scripts\Windows\Maintenance\Invoke-SystemUpgrade.ps1Notes:
- SFC and DISM run in the background — they start immediately (step 3) but their windows are hidden. They may still be running when the Chocolatey and pip steps complete.
- The inventory save uses
choco list --local-only(-lois an alias; both forms work). -
choco upgrade all -ywill restart services affected by upgraded packages. Run interactively so you can respond to any prompts Chocolatey passes through. - Windows Update via COM (
Microsoft.Update.Session) installs updates but does not reboot. Result code 3 means "updates installed, reboot may be required."
What it does: Runs chkdsk C: /f /r on the C: drive.
-
/f— fixes filesystem errors. -
/r— locates bad sectors and recovers readable data.
Parameters: None. Auto-elevates if not already admin.
Usage:
.\Scripts\Windows\Maintenance\Invoke-DiskCheck.ps1Notes:
- On a live (in-use) C: drive,
chkdsk /rcannot run immediately. It schedules a check at the next system boot and prompts you to confirm. - The check can take a long time on large or degraded drives — expect 30–120+ minutes on boot.
-
/rimplies/f.
What it does: Queries the Application and System Windows Event Logs for Level 2 (Error) events within a configurable lookback window, groups by source, and highlights noisy sources that exceed a configurable error threshold.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
-DaysBack |
int |
7 |
How many days back to search |
-ErrorThreshold |
int |
10 |
Sources with more than this many errors are printed in detail |
Usage:
# Default: 7 days, flag sources with >10 errors
.\Scripts\Windows\Maintenance\Get-ErrorReport.ps1
# Custom: 14 days, flag sources with >5 errors
.\Scripts\Windows\Maintenance\Get-ErrorReport.ps1 -DaysBack 14 -ErrorThreshold 5Output: For each noisy source, prints a table of the first 10 events (TimeCreated, Id, Message). Ends with a total error count across all sources.
Requirements: Read access to the Windows Event Log. Administrator access is recommended because some log entries require elevated permissions to read.
What it does: A reference script — a commented collection of the most useful sfc.exe and dism.exe commands for diagnosing and repairing Windows.
This script is not meant to be run top-to-bottom. Open it, read the commands, and run the ones you need individually.
Included commands:
| Command | What it does |
|---|---|
sfc /scannow |
Scan and repair all protected system files |
sfc /verifyonly |
Scan without repairing |
sfc /scanfile=<path> |
Scan and repair a single file |
sfc /offwindir=... /offbootdir=... /scanfile=... |
Scan an offline Windows installation |
| Command | What it does |
|---|---|
dism /online /cleanup-image /restorehealth |
Repair the Windows image (downloads from Windows Update if needed) |
dism /online /cleanup-image /startcomponentcleanup |
Clean up the WinSxS folder |
dism /online /cleanup-image /startcomponentcleanup /resetbase |
Deep cleanup — resets base, cannot be undone |
dism /online /cleanup-image /analyzecomponentstore |
Analyze WinSxS and report potential savings |
dism /online /get-packages |
List all installed packages and their states |
# 1. Repair the Windows image first
dism /online /cleanup-image /restorehealth
# 2. Then use the healthy image to repair system files
sfc /scannowRunning SFC before DISM risks it sourcing repairs from an already-corrupted image. Always DISM first.