Created
August 27, 2012 21:11
-
-
Save jbutz/3492279 to your computer and use it in GitHub Desktop.
Remove Cisco Voicemails >= 30 days old from the Downloads folder
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
# Remove Cisco Voicemails >= 30 days old from the Downloads folder | |
# 08/27/2012 | |
## Use the debug value to change whether or not you delete things or say what you would delete | |
$debug = $TRUE | |
## Do you want to say which files you deleted? | |
$output = $TRUE | |
## Set the folder to the base directory you want to start your searches in | |
$folder = "C:\" | |
$files = Get-ChildItem $folder -recurse -include VoiceMessage*.wav # This looks for files recursively in the folder that start with VoiceMessage and end with .wav | |
Foreach($x in $files) | |
{ | |
if($x.fullname.Contains("My Documents\Downloads")) # Make sure we are in the Downloads folder in someone's My Documents folder | |
{ | |
$access = $x | % {(get-date) - $_.LastAccessTime } # Get how long ago they were accessed | |
if($access.days -ge 30) # Was it >= 30 days ago? | |
{ | |
if($output) | |
{ | |
write-host $x.fullname " was last accessed " $access.days "days ago" | |
} | |
if($debug) | |
{ | |
$x | Remove-Item -whatif | |
} | |
else | |
{ | |
$x | Remove-Item | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment