Clear Cache and Temporary Files

SOTI MobiControl
Windows

Over time, cached data and temporary files can accumulate on Windows devices, causing slowdowns and impacting system performance. The Clear Cache and Temporary Files script allows IT administrators to remotely clear unnecessary cached data, freeing up disk space and improving the efficiency of device operations. Regularly clearing cache helps speed up web browsing, reduces system lag, and can assist in troubleshooting by removing outdated files that may interfere with the device’s functionality. By automating this task, admins can maintain optimal device performance across the organization.

Important:
  • It is recommended to test the script on a local/ test machine for its purpose and effects. 
  • SOTI MobiControl will not be responsible for any damage/loss to the data/setup based on the behavior of the script.

Clear recycle bin

1 $Path = 'C' + ':\$Recycle.Bin'
2 Get-ChildItem $Path -Force -Recurse -ErrorAction SilentlyContinue |
3 Remove-Item -Recurse -exclude *.ini -ErrorAction SilentlyContinue
4 write-Host "Recycle Bin is empty."

Clear temporary files

1 $objShell = New-Object -ComObject Shell.Application
2 $objFolder = $objShell.Namespace(0xA)
3 $WinTemp = "c:\Windows\Temp\*"
4 #1# Remove Temp Files
5 write-Host "Removing Temp" -ForegroundColor Green
6 Set-Location “C:\Windows\Temp”
7 Remove-Item * -Recurse -Force -ErrorAction SilentlyContinue
8 Set-Location “C:\Windows\Prefetch”
9 Remove-Item * -Recurse -Force -ErrorAction SilentlyContinue
10 Set-Location “C:\Documents and Settings”
11 Remove-Item “.\*\Local Settings\temp\*” -Recurse -Force -ErrorAction SilentlyContinue
12 Set-Location “C:\Users”
13 Remove-Item “.\*\Appdata\Local\Temp\*” -Recurse -Force -ErrorAction SilentlyContinue
14 #2# Running Disk Clean up Tool
15 write-Host "Running the Windows Disk Clean up Tool" -ForegroundColor White
16 cleanmgr /sagerun:1 | out-Null
17 $([char]7)
18 Sleep 3
19 write-Host "Cleanup task complete!" -ForegroundColor Yellow
20 Sleep 3
21 ##### End of the Script #####

Was this helpful?

Need more help?
Ask Community