Skip to content

Instantly share code, notes, and snippets.

@focusmade
Last active April 23, 2021 04:31
Show Gist options
  • Save focusmade/66d34d2321a6c82abdca5a5480871965 to your computer and use it in GitHub Desktop.
Save focusmade/66d34d2321a6c82abdca5a5480871965 to your computer and use it in GitHub Desktop.
# Defines the '365 days old' (today's date minus 365)
$age = (Get-Date).AddDays(-365)
# Get all the files in the Downloads folder and subfolders | foreach file
Get-ChildItem -Path $env:SystemDrive\Users\*\Downloads -Recurse -Force | foreach{
# if creationtime is 'le' (less or equal) than 365 days
if ($_.CreationTime -le $age){
# Write-Output "Older than 365 days - $($_.name)"
# remove the item
Remove-Item $_.fullname -Force -Verbose
}else{
# Write-Output "Less than 365 days old - $($_.name)"
# Do stuff
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment