This is a small but effective function.
It will delete most of the stuff in your temp dir.
Use with close option to close all open programs
before you clean the temp dir. It will not delete
open/locked files.
The function can also be downloaded from the Download section.
http://poweradmin.se/blog/download
# Clean Temp Function # By Fredrik Wall, fredrik@poweradmin.se # http://www.poweradmin.se/blog # # Last modified: 2009-12-14 # Tested on: Windows 7, Windows Server 2008 R2 # Revision history: # 2009-12-14 ADD: -ErrorAction SilentlyContinue # ADD: Close option # Example of calling the function: # Clean-Temp # Clean-Temp 'Close' # function Clean-Temp { param($status) if ($status -eq 'close') { # Some programs that often uses temp dir for temp files process iexplore* | kill process outlook* | kill process word* | kill process excel* | kill process msn* | kill $myTemp = "$Env:temp" Get-Childitem $myTemp | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue $myTemp = $null } else { $myTemp = "$Env:temp" Get-Childitem $myTemp | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue $myTemp = $null } }
No related posts.