Skip to content

Instantly share code, notes, and snippets.

@samonzeweb
Created March 9, 2018 13:41
Show Gist options
  • Save samonzeweb/2fd05786b783937399e8aec4fa57a649 to your computer and use it in GitHub Desktop.
Save samonzeweb/2fd05786b783937399e8aec4fa57a649 to your computer and use it in GitHub Desktop.
Remove folders created more than X days in PowerShell
# 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