Quantcast
Viewing all articles
Browse latest Browse all 15370

Delete Files older than 30 days

I need a script to delete all files in a folder older than 30 days, leaving any files, and and folders with files in them that are less than 30 days old.

I found the following powershell script that can almost do this, however, the problem with this script as it is currently written is that if the folder is older than 30 days it will delete the folder and all data in it, even if that data is only a day old.

get-childitem d:\temp1 | where {$_.CreationTime -lt (date).adddays(-30)} | remove-item -recurse

http://cornasdf.blogspot.com/2010/03/powershell-delete-files-older-than-x.html

Your help would be much appreciated.


Viewing all articles
Browse latest Browse all 15370

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>