As professional organizing consultant Marie Kondo says, “the objective of cleaning is not just to clean, but to feel happiness living within that environment.”
To keep your clients happy and their computers running at optimal speed, it’s vital to take care of a computer’s maintenance needs at least once every month.
While once a month may seem like a lot, with this straightforward script, you can conveniently preset a series of cleanup maintenance tasks on the system.
The script’s preset options include creating a restore point (a saved ‘snapshot’ of a computer’s data at a specific point in time), rebooting the system, deleting current user and system temporary files, running Windows Disk Cleanup, and rebooting again once complete.
Using Windows Disk Cleanup, this script will only clean the temporary directory of the user executing the script. Other user accounts will not have their temporary files deleted.
So, are you ready to clean up the files no one needs anymore?
The Script:
Atera does not guarantee the integrity, availability, security, virus-free, safety, lawfulness, non-infringement, rights’ status, or functionality of the scripts. The use of the shared scripts is at your own risk. Scripts are provided “AS IS”. *
#Weekly Maintenance
#Create Restore Point
#Reboot Computer
#Delete Temp Files
#Empty Temp Folders
#Run Full Disk Cleanup unattended
#Reboot
# 1.creating the restore point
Checkpoint-Computer -Description "Weekly Maintanence" -RestorePointType "MODIFY_SETTINGS"
Write-Host "System Restore Point created successfully"
#3.Delete Temp Files
$objShell = New-Object -ComObject Shell.Application
$objFolder = $objShell.Namespace(0xA)
$temp = get-ChildItem "env:\TEMP"
$temp2 = $temp.Value
$WinTemp = "c:\Windows\Temp\*"
# Remove temp files located in "C:\Users\USERNAME\AppData\Local\Temp"
write-Host "Removing Junk files in $temp2." -ForegroundColor Magenta
Remove-Item -Recurse "$temp2\*" -Force -Verbose
# Remove Windows Temp Directory (Folder)
write-Host "Removing Junk files in $WinTemp." -ForegroundColor Green
Remove-Item -Recurse $WinTemp -Force
#5. Running Disk Clean up Tool
write-Host " Running Windows disk Clean up Tool" -ForegroundColor Cyan
cleanmgr /sagerun:1 | out-Null
$([char]7)
Sleep 1
$([char]7)
Sleep 1
write-Host "Clean Up Task completed !"
#?AutoReboot
#6.Reboot Computer
#Restart-Computer TODO - Syncro cannot currently reboot a computer from scripts.
Technical Notes:
1. This script retrieves the user temporary directory from the environment variable in PowerShell directly, and as such, will only clean the temporary directory of the user executing the script. Other user accounts will not have their temporary files deleted.
2. The script invokes Windows Disk Cleanup (cleanmgr) with a sagerun task preset of 1. This will only work as expected if a task preset for 1 has previously been configured.