September 4th, 2015

PowerTip: Use PowerShell to Clean Up Temp Files

Doctor Scripto
Scripter

Summary: Use Windows PowerShell to delete temporary files.

Hey, Scripting Guy! Question How can I use Windows PowerShell to clean up a bunch of files that are stored in my temp directory?

Hey, Scripting Guy! Answer Use the Get-ChildItem cmdlet (dir is an alias), point it to the $env:temp directory, and pipe the results
           to the Remove-Item cmdlet, for example:

dir $env:TEMP -Recurse | Remove-Item -Force -Recurse

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.