AI script for pc health

Being a coding illiterate I asked AI to write a batch file to periodically do some basic maintenance on my PC… I attach the result - it has been running on my PC [old hybrid 5xHDD 12Gb RAM Win10 blah blah blah] for months without problems, see attached :slight_smile:
it is a .bat file - somehow I cant load it but here is the content:

@echo off
:: Windows 10 Maintenance Script
:: Ensure the script is run as administrator

:: Check if running as administrator
whoami /groups | find “S-1-16-12288” >nul || (
echo Please run this script as an administrator.
pause
exit /b
)

:: Step 1: Run CHKDSK (only fix mode, no recovery or bad sector scan)
echo Running CHKDSK on the system drive…
chkdsk C: /F

:: Step 2: Run System File Checker (SFC)
echo Running System File Checker…
sfc /scannow

:: Step 3: Clean up temporary and unnecessary files
echo Cleaning up temporary and unnecessary files…
del /s /q “%temp%*” >nul 2>&1
rd /s /q “%temp%” >nul 2>&1
mkdir “%temp%”
cleanmgr /sagerun:1

:: Step 4: Clear Windows Update cache
echo Clearing Windows Update cache…
net stop wuauserv >nul 2>&1
net stop cryptSvc >nul 2>&1
net stop bits >nul 2>&1
net stop msiserver >nul 2>&1
rd /s /q “%windir%\SoftwareDistribution” >nul 2>&1
rd /s /q “%windir%\System32\catroot2” >nul 2>&1
net start wuauserv >nul 2>&1
net start cryptSvc >nul 2>&1
net start bits >nul 2>&1
net start msiserver >nul 2>&1

:: Step 5: Run Disk Cleanup for all users
echo Running Disk Cleanup…
dism /online /cleanup-image /startcomponentcleanup
dism /online /cleanup-image /analyzecomponentstore

:: Step 6: Delete old Windows setup files
echo Deleting old Windows setup files…
dism /online /cleanup-image /startcomponentcleanup /resetbase

:: Step 7: Check for Windows Updates
echo Checking for Windows Updates…
start ms-settings:windowsupdate

:: Step 8: Defragment the drive (if not SSD)
echo Checking drive type for defragmentation…
wmic diskdrive get mediatype,caption | find “SSD” >nul
if errorlevel 1 (
echo Running defragmentation on HDD…
defrag C: /O
) else (
echo SSD detected. Skipping defragmentation…
)

:: Step 9: Create a Restore Point
echo Creating a system restore point…
powershell -command “Checkpoint-Computer -Description ‘Maintenance Restore Point’ -RestorePointType ‘MODIFY_SETTINGS’”

:: Final Step: Display completion message
echo Maintenance tasks completed successfully!
pause

1 Like