Schedule Task to Empty Windows Temp Folder
In this post, we will talk about Windows Temp Folder and how to empty it. which by default exist under system partition and it may decrease the system partition size because it’s size is increasing every day based in your activities in the server or PC and this may affect services that need free space in the system partition like Exchange Hub transport queue …etc.
Firstly, we will define Temp Folder and why it increasing as per Microsoft description:
A Windows temporary file is created under the following three circumstances:
1. Windows Desktop applications, such as Write, and multiple document interface (MDI) applications, such as Excel, create temporary files to handle necessary user editing. Because a Desktop application cannot have multiple documents open at once, it must immediately create a temporary file that allows you to undo any editing. MDI applications create temporary files only when necessary (for related editing), rather than for every worksheet that is open.
2. When you run an MS-DOS-based standard application with Windows/286, Windows/286 creates a temporary file (for example, ~PIFCHFA.TMP) so that it can swap to disk to make room for other applications to use memory.
3. When you print from Windows or any Windows-based application with the spooler enabled, Windows creates temporary files on the hard disk. Windows spools the print job to the temporary file and then sends it to the appropriate printer as a background operation.
Please refer to MS article for more info https://support.microsoft.com/en-us/kb/92635
Secondly, we will see how to create schedule task for cleaning up this folder
Requirements: Service Account with Local admin privilege and password set to never expired
Please follow below Steps to create the script and schedule task:
Set-Location “C:\Windows\Temp”
Remove-Item * -recurse -force
Then save the file as CleanTempFolder.ps1