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
$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
Remove-Item ".\*\AppData\Local\Microsoft\Windows\INetCache\*" -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
2) Clear Recycle Bin
$Path = 'C' + ':\$Recycle.Bin'
Get-ChildItem $Path -Force -Recurse -ErrorAction SilentlyContinue |
Remove-Item -Recurse -exclude *.ini -ErrorAction SilentlyContinue
write-Host "Recycle Bin is empty."3) Batch script
@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!