Created
March 6, 2015 01:49
-
-
Save bradymholt/31aac80b1649a6111f50 to your computer and use it in GitHub Desktop.
Deletes directories older than specified number of 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
param ([Parameter(Mandatory=$True)] $clean_path, [Parameter(Mandatory=$True)] $search_pattern, [Parameter(Mandatory=$True)] $max_days) | |
# 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)) | |
Get-ChildItem $clean_path | Where {$_.Attributes -eq 'Directory'} | ` | |
Foreach-Object{ | |
Write-Host $_.FullName | |
Get-ChildItem $_.FullName | Where {$_.Attributes -eq 'Directory'} | Where-Object { $_.LastWriteTime -lt $del_date } | Remove-Item -Recurse | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment