-
Notifications
You must be signed in to change notification settings - Fork 2
/
deloldtemp.ps1
19 lines (16 loc) · 1.42 KB
/
deloldtemp.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#dennyhalim.com #removing ALL files and folders with following conditions:
# inside folder named: Temp
# location: %temp% and %windir%\temp
# files/folders older than 70 days
# remove without warning
# remove the option '-WhatIf' to perform real action
# WARNING!! DANGER!!! if you remomve -WhatIf option then anything will be removed without warning. no question asked!
# if -WhatIf option remains, then nothing removed
Get-ChildItem -Path "$env:windir\Temp" -Recurse | Where-Object{$_.LastAccessTime -lt (Get-Date).AddDays(-70)} | Remove-Item -Verbose -Force -Recurse -WhatIf >> "$env:windir\Logs\del.log"
Get-ChildItem -Path "$env:public\..\*\AppData\Local\Temp" -Recurse | Where-Object{$_.LastAccessTime -lt (Get-Date).AddDays(-70)} | Remove-Item -Verbose -Force -Recurse -WhatIf >> "$env:windir\Logs\del.log"
# remove ALL browser cache
Get-ChildItem -Path "$env:public\..\*\AppData\Local\Google\Chrome\User Data\Default\Cache" -Recurse | Remove-Item -Verbose -Force -Recurse -WhatIf >> "$env:windir\Logs\del.log"
Get-ChildItem -Path "$env:public\..\*\AppData\Local\Microsoft\Windows\Temporary Internet Files" -Recurse | Remove-Item -Verbose -Force -Recurse -WhatIf >> "$env:windir\Logs\del.log"
Get-ChildItem -Path "$env:public\..\*\AppData\Local\Mozilla\Firefox\Profiles\*.default\cache2" -Recurse | Remove-Item -Verbose -Force -Recurse -WhatIf >> "$env:windir\Logs\del.log"
#cmd:
#forfiles.exe -p %temp% -s -m * -d -70 -c "cmd /c echo @path"