Forum Discussion
Simple way to remove or delete temporary files in Windows 10
Using PowerShell scripts is a powerful and flexible way to delete temporary files on Windows 10. It allows you to automate the cleanup process, especially if you want to perform regular maintenance or customize what gets deleted.
How to Use PowerShell Scripts to Delete Temporary Files
Basic Script to Delete User and System Temp Files
Here is a simple PowerShell script that deletes temporary files from both the user and system temp folders:
# Delete user temp files
Remove-Item -Path "$env:TEMP\*" -Recurse -Force -ErrorAction SilentlyContinue
# Delete system temp files
Remove-Item -Path "C:\Windows\Temp\*" -Recurse -Force -ErrorAction SilentlyContinue
Write-Output "Temporary files deleted successfully."
How to Run the Script
1. Open Notepad:
Paste the script above into a new Notepad file.
2. Save as a PowerShell Script:
Save the file with a .ps1 extension, e.g., CleanTempFiles.ps1.
3. Run PowerShell as Administrator:
Search for PowerShell in the Start menu.
Right-click Windows PowerShell and select Run as administrator.
4. Set Execution Policy (if needed):
To allow running scripts, execute:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
Confirm when prompted.
5. Execute the Script:
Navigate to the folder containing your script:
cd path\to\your\script
Run the script:
.\CleanTempFiles.ps1