Created
April 30, 2013 07:23
-
-
Save ergunozyurt/5487132 to your computer and use it in GitHub Desktop.
Delete Files and Folders Older Than X Days (http://elderec.org/2012/02/scripting-delete-files-and-folders-older-than-x-days/)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # set folder path | |
| $dump_path = "d:\temp" | |
| # set min age of files | |
| $max_days = "-1" | |
| # get the current date | |
| $curr_date = Get-Date | |
| # determine how far back we go based on current date | |
| $del_date = $curr_date.AddDays($max_days) | |
| # delete the files | |
| Get-ChildItem $dump_path -Recurse | Where-Object { $_.LastWriteTime -lt $del_date } | Remove-Item |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment