Created
March 9, 2018 13:41
-
-
Save samonzeweb/2fd05786b783937399e8aec4fa57a649 to your computer and use it in GitHub Desktop.
Remove folders created more than X days in PowerShell
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
# Script parameters | |
$pathToClean = 'C:\paht\to\somewhere' | |
$maxDays = 5 | |
# Computed values, don't touch below | |
$dateLimit = (Get-Date).AddDays(-1 * $maxDays) | |
Get-ChildItem $pathToClean | | |
Where { $_.CreationTime -lt $dateLimit } | | |
Remove-Item -Recurse #-WhatIf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment