Skip to content

PowerShell Script to Check/Fix OS System Components

Published: at 06:40 AM

If you’re experiencing system issues or errors related to Windows components, running a script to check and fix your OS system components can help. Below is a PowerShell script that automates this process:

Script

SC config trustedinstaller start=auto

net stop bits
net stop wuauserv
net stop msiserver
net stop cryptsvc
net stop appidsvc

Ren %Systemroot%\SoftwareDistribution SoftwareDistribution.old
Ren %Systemroot%\System32\catroot2 catroot2.old

regsvr32.exe /s atl.dll
regsvr32.exe /s urlmon.dll
regsvr32.exe /s mshtml.dll

netsh winsock reset
netsh winsock reset proxy

rundll32.exe pnpclean.dll,RunDLL_PnpClean /DRIVERS /MAXCLEAN

dism /Online /Cleanup-image /ScanHealth
dism /Online /Cleanup-image /CheckHealth
dism /Online /Cleanup-image /RestoreHealth
dism /Online /Cleanup-image /StartComponentCleanup

Sfc /ScanNow

net start bits
net start wuauserv
net start msiserver
net start cryptsvc
net start appidsvc

This PowerShell script is designed to diagnose and repair common Windows system issues. It performs a series of checks and fixes to ensure optimal system health.

Key Actions Performed by the Script:

  1. Starts the TrustedInstaller Service: This service is crucial for system updates and installations.
  2. Stops Windows Update Services: This prevents interference during the repair process.
  3. Deletes Temporary System Files: Removes old software distribution and catroot2 folders, which can sometimes cause issues.
  4. Re-registers DLLs: Re-registers essential DLLs to resolve potential errors.
  5. Resets Winsock Catalog: Fixes Winsock-related issues that might disrupt network connectivity.
  6. Cleans up Device Driver Installation: Removes old driver installations that could cause conflicts.
  7. Scans and Repairs System Files: Uses the DISM tool to check and repair system files for corruption.
  8. System File Checker: Scans and repairs system files for integrity.
  9. Restarts Stopped Services: Restores the stopped services to their original state.

How to Use the Script:

  1. Create a New Text File: Open a text editor like Notepad and paste the script code.
  2. Save as a .bat File: Save the file with a .bat extension (e.g., system_repair.bat).
  3. Run the Script: Double-click the saved .bat file to execute the script.

Important Considerations:


Previous Post
Penguins Gallery - info icon appears if caption is present using :has()
Next Post
Star Wars Scroll