Skip to content

A Windows PowerShell script to clean up the temp folder, for a very specific issue I am encountering with lots and lots of folders being created and left behind by cleanmgr.exe that were filling up my hard disk.

Notifications You must be signed in to change notification settings

larspassic/CleanUp-Temp.ps1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CleanUp-Temp.ps1

Image of CleanUp-Temp.ps1 running A script to clean up the temp folder, for a very specific issue I am encountering with lots and lots of folders being created and left behind by cleanmgr.exe

Here is what cleanmgr.exe has been leaving behind in my temp directory, eventually completely filling up my hard disk:

Image of the folders that cleanmgr.exe is leaving behind

Here is what each of those folders looks like inside:

Image of one of the folders that cleanmgr.exe is leaving behind

These folders are usually about 9.6 MB each, but if there exists 15,000+ of these folders, you can see how the disk space will fill up quickly.

I used ProcMon from sysinternals to monitor the temp directory, and eventually found that cleanmgr.exe was the culprit and was creating these folders, and not deleting them after it was finished.

I tried using the built-in Disk Cleanup Utility (cleanmgr.exe) as well as Storage Sense, but neither of them succeeded in removing these particular folders from my temp directory.

So I wrote this PowerShell script to look for the patterns that these folders follow and remove them from the temp folder, to clean up what cleanmgr.exe left behind.

There is some inherent risk with programmatically mass-deleting folders, so please be careful with this script.

About

A Windows PowerShell script to clean up the temp folder, for a very specific issue I am encountering with lots and lots of folders being created and left behind by cleanmgr.exe that were filling up my hard disk.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published