- 02 Feb 2024
- 1 読む分
- 印刷する
- PDF
Clear Temporary Files on Windows devices
- 更新日 02 Feb 2024
- 1 読む分
- 印刷する
- PDF
Clearing caches on a Windows device becomes particularly beneficial when experiencing performance issues or a slowdown, often noticeable after extended internet usage, Windows updates, or prolonged periods without a system restart. Depending on your settings, caches can accumulate substantial data, occupying significant disk space and consequently slowing down web browsing and routine tasks. Regularly clearing your cache contributes to enhanced system efficiency for various reasons, ultimately leading to an overall boost in your computer's performance.
The following PowerShell script helps the IT Admins to remotely clear cache and temporary files on their managed Windows devices.
Create a file on your desktop, for example, remove_temporary_files.ps1 and open it in a text editor like notepad++
Copy the contents below to the file or click here to download the file.
$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 #####
Follow our guide to upload & publish the PowerShell script using Scalefusion Dashboard.
Please note you will have to reboot the device once script is successfully executed.
Please note that to use the PowerShell scripts, the Scalefusion MDM Agent Application must be installed on the device(s). Please follow our guide to publish and install the Scalefusion MDM Agent Application.
Notes:
The scripts and their contents are sourced from various albeit authenticated Microsoft sources and forums.
Please validate the scripts on a test machine before deploying them on all your managed devices.
Scalefusion has tested these scripts, however, Scalefusion will not be responsible for any loss of data or system malfunction that may arise due to the incorrect usage of these scripts.