Category filter
Script to clear cache and temporary files on Windows devices
Clearing all caches in Windows usually helps if your device is slowing down or exhibiting suboptimal performance. This usually happens when you’ve been on the internet for a while, installed Windows updates, or haven’t reset your computer in a long time.
For several reasons, clearing your cache regularly enhances the efficiency of your system. Depending on your settings, a cache can get rather large and take up a lot of disc space on your computer. The more data saved in the cache, the slower your computer will browse the web or do routine tasks. Delete the cache data to aid debugging, improve web page loading times, and boost your computer’s performance.
Using Hexnode, you can deploy scripts to effortlessly delete all temporary files and directories as well as empty the recycle bin.
PowerShell scripts
1) Remove temporary files
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
$objShell = New-Object -ComObject Shell.Application $objFolder = $objShell.Namespace(0xA) $WinTemp = "c:\Windows\Temp\*" #1# Remove Temp Files write-Host "Removing Temp" -ForegroundColor Green Set-Location “C:\Windows\Temp” Remove-Item * -Recurse -Force -ErrorAction SilentlyContinue Set-Location “C:\Windows\Prefetch” Remove-Item * -Recurse -Force -ErrorAction SilentlyContinue Set-Location “C:\Documents and Settings” Remove-Item “.\*\Local Settings\temp\*” -Recurse -Force -ErrorAction SilentlyContinue Set-Location “C:\Users” Remove-Item “.\*\Appdata\Local\Temp\*” -Recurse -Force -ErrorAction SilentlyContinue #2# Running Disk Clean up Tool write-Host "Running the Windows Disk Clean up Tool" -ForegroundColor White cleanmgr /sagerun:1 | out-Null $([char]7) Sleep 3 write-Host "Cleanup task complete!" -ForegroundColor Yellow Sleep 3 ##### End of the Script ##### |
2) Clear Recycle Bin
1 2 3 4 |
$Path = 'C' + ':\$Recycle.Bin' Get-ChildItem $Path -Force -Recurse -ErrorAction SilentlyContinue | Remove-Item -Recurse -exclude *.ini -ErrorAction SilentlyContinue write-Host "Recycle Bin is empty." |
Batch script
1 2 3 4 5 6 7 |
@echo off echo is clearing system junk files, please wait... del /f /s /q %windir%\prefetch\*.* & rd /s /q %windir%\temp & md %windir%\temp echo clear system garbage is complete! |