Last active
December 19, 2017 19:01
-
-
Save ezeeetm/f220e1c91b57ceeac1aedce102e17206 to your computer and use it in GitHub Desktop.
for nate...
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
<# | |
.SYNOPSIS | |
deletes files on login by file age and a list of file name regular expressions | |
.DESCRIPTION | |
srsly man, that's all it does. | |
.EXAMPLE | |
.\dloadCleanup.ps1 | |
#> | |
# change these values to suit your needs | |
$regexList = @("^imageLinkProcessor.*pdf$", "^message.*mp3$") | |
$ageInDays = 14 | |
# /change values | |
# don't change these | |
$downloadsPath = "$env:USERPROFILE\Downloads" | |
$deleteBeforeDate = (Get-Date).AddDays(-$ageInDays) | |
foreach ($regex in $regexList) | |
{ | |
$offendingFiles = Get-ChildItem $downloadsPath | Where-Object {$_.Name -match $regex -and $_.CreationTime -lt $deleteBeforeDate} | |
foreach ($offendingFile in $offendingFiles) | |
{ | |
Remove-Item -Force $offendingFile.FullName | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment