LEARN THE LATEST WEBSITE DESIGN Join Now!

Script to clear cache and temporary files on Windows devices

Script to clear cache and temporary files on Windows devices
Please wait 0 seconds...
Scroll Down and click on Go to Link for destination
Congrats! Link is Generated

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.

Disclaimer:

The sample scripts provided below are adapted from third-party open-source sites.

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! 

About the Author

Hey there! I'Abdullah, a professional part-time blogger. Join me as I share informative and technical content to help you learn something new. ✨ #BloggerLife #TechTips #LearnSomethingNe

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.