This repo contains standalone scripts to automatically detect and repair corruption(s) found in the system components and filesystem of a Windows 11 operating system (OS). The scripts uses only tools that come pre-packaged with the Windows 11 Home OS and does not require installation of any third-party software.
For Command Prompt users, use FixWindowsSystem.bat.
For PowerShell users, use FixWindowsSystem.ps1. As PowerShell 5.1 is packaged
together with Windows 11, this PowerShell script has been written to use only
PowerShell 5.1 commands.
The script repairs Windows in the following steps:
-
Remove unused driver packages in Windows using
rundll32.exe pnpclean.dll,RunDLL_PnpClean /DRIVERS /MAXCLEAN
-
Detect and repair errors found in Windows component store (WinSxS) using the Repair-WindowsImage cmdlet or Dism.exe tool.
-
Detect and repair errors found in Windows system files using the sfc.exe tool. There seems to be no PowerShell equivalent for this tool.
-
Detect and repair corruption in Windows file system using Repair-Volume cmdlet or chkdsk tool.
-
Remove superseded versions of updated components in Windows component store using the
Repair-Volumecmdlet orDism.exetool. -
Detect and repair errors found in disk volume using Optimize-Volume cmdlet or defrag tool.
Note: If no errors are found in disk volume, the script will perform disk optimisation by executing defrag for HDD and retrim for SSD accordingly.
To use the batch file on your Windows 11 system
-
Download
FixWindowsSystem.batto computer. -
Right-click on the batch file and select "Run as administrator". A UAC prompt will appear to request for elevation to run the script with Administrator privileges.
-
Alternatively, open Command Prompt with Administrator privileges.
FixWindowsSystem.bat
Important
If your script is unable to execute properly on your Windows machine, you may need to relax your PowerShell Execution Policy or unblock your script from Smart App Control. See the sections below for more information on how to do this.
To use the PowerShell script on your Windows 11 system
-
Download
FixWindowsSystem.ps1to your Downloads folder. -
Right-click on the script and select "Run with PowerShell". A UAC prompt will appear to request for elevation to run the script with Administrator privileges.
-
Alternatively, open PowerShell Terminal with Administrator privileges and execute the script.
.\FixWindowsSystem.ps1
If you use the default PowerShell Execution Policy on your Windows machine,
the policy for local machine is set to Undefined. This will cause PowerShell
scripts to be blocked and they will not be able to execute locally your machine.
In order to execute PowerShell scripts locally on your Windows machine, you will need to perform a one-time relaxing of this policy using PowerShell Terminal with Administrator privileges with the following command.
Set-ExecutionPolicy -ExecutionPolicy BypassVerify that your execution policy for LocalMachine is updated to Bypass.
Get-ExecutionPolicy -ListThe expected output should be similar to below.
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser Undefined
LocalMachine Bypass
When you download a PowerShell script and want to execute it on your machine, Smart App Control in your Windows may block the script from executing and show a security warning about running scripts downloaded from the internet.
If you right-click the PowerScript file to execute it, the security warning appears as a pop-up with the following message:
Smart App Control blocked a file that may be unsafe
This file was blocked because files of this type from the internet can be
dangerours.
Learn more
Alternatively, if you opened PowerShell Terminal and tried to execute the script, you will see the following security warning appear in the terminal:
Security warning
Run only scripts that you trust. While scripts from the internet can be
useful, this script can potentially harm your computer. If you trust this
script, use the Unblock-File cmdlet to allow the script to run without this
warning message. Do you want to run C:\...\FixWindowsSystem.ps1?
In both cases above, you can mark the script as "safe to run" with the command below to unblock the script from Smart App Control.
Unblock-File .\FixWindowsSystem.ps1