Skip to content

Instantly share code, notes, and snippets.

@Greyeye
Last active December 11, 2015 01:59
Show Gist options
  • Save Greyeye/4527677 to your computer and use it in GitHub Desktop.
Save Greyeye/4527677 to your computer and use it in GitHub Desktop.
single company version of https://gist.github.com/4527657
#change the number to filter the files OLDER than dates, eg, 90 means select files older than 90
$days = 90
#change silent to $true, if you want to see the remote-item in progress.
$silent = $false
#change profile location
$profileLocation = "E:\Profiles\XA6"
$now=get-date
#to target recent items change path below to
# recent = \UPM_Profile\AppData\Roaming\Microsoft\Windows\Recent
# cookies = \UPM_Profile\AppData\Roaming\Microsoft\Windows\Cookies
$targetPath = "\UPM_Profile\AppData\Roaming\Microsoft\Windows\Cookies"
$totalFiles = 0
if ($silent){
$ea="Silentlycontinue"
} else {$ea="Continue"}
foreach($username in (Get-ChildItem -path $profileLocation))
{
#once usernames are obtained, build user path to target cookies.
$userpath = $profileLocation+"\"+$username+$targetPath
#build date filter, $days is specified at the top.
$datefilter=$now.adddays(-$days)
#select all files older than specified date $days, but will not select desktop.ini and folder.
foreach ($file in get-childitem $userpath -recurse -force | where {$_.PSIsContainer -eq $false -and $_.lastwritetime -le $datefilter -and $_.name -ne "desktop.ini"})
{
#write-host "$userpath\$file"
$totalFiles = $totalFiles +1
#write-host $totalFiles
remove-item -literalPath $file.fullname -force -ea $ea
}#end for
}
write-host "total $totalFiles has been removed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment