Handy script to delete files from the temp directory

This is handy.  It will delete all files of the given extension from the temp folder that are
more than the given number of days old


 

Get-ChildItem -Path $env:Temp | where{($_.LastAccessTime -lt
((Get-Date).AddDays(-2))) -and ($_.Extension -eq ".tmp"
)} | Remove-Item -WhatIf

 

Change .tmp to another extension and change the number of days to match your needs.

Remove the -Whatif if you like the results.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s