Last active
April 23, 2021 04:31
-
-
Save focusmade/66d34d2321a6c82abdca5a5480871965 to your computer and use it in GitHub Desktop.
This file contains 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
# 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