ClearBrowserCaches.ps1 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #Write-Host -ForegroundColor Green "SECTION 1: Getting the list of users"
  2. #Write-Host -ForegroundColor yellow "Exporting the list of users to c:\users\%username%\users.csv"
  3. # List the users in c:\users and export to the local profile for calling later
  4. dir C:\Users | select Name | Export-Csv -Path C:\users\$env:USERNAME\users.csv -NoTypeInformation
  5. $list=Test-Path C:\users\$env:USERNAME\users.csv
  6. ""
  7. #Write-Host -ForegroundColor Green "SECTION 2: Beginning Script..."
  8. if ($list) {
  9. #Clear Mozilla Firefox Cache
  10. #Write-Host -ForegroundColor Green "SECTION 3: Clearing Mozilla Firefox Caches"
  11. Write-Host -ForegroundColor cyan
  12. Import-CSV -Path C:\users\$env:USERNAME\users.csv -Header Name | foreach {
  13. Remove-Item -path C:\Users\$($_.Name)\AppData\Local\Mozilla\Firefox\Profiles\*.default\cache\* -Recurse -Force -EA SilentlyContinue
  14. Remove-Item -path C:\Users\$($_.Name)\AppData\Local\Mozilla\Firefox\Profiles\*.default\cache\*.* -Recurse -Force -EA SilentlyContinue
  15. Remove-Item -path C:\Users\$($_.Name)\AppData\Local\Mozilla\Firefox\Profiles\*.default\cache2\entries\*.* -Recurse -Force -EA SilentlyContinue
  16. Remove-Item -path C:\Users\$($_.Name)\AppData\Local\Mozilla\Firefox\Profiles\*.default\thumbnails\* -Recurse -Force -EA SilentlyContinue
  17. Remove-Item -path C:\Users\$($_.Name)\AppData\Local\Mozilla\Firefox\Profiles\*.default\cookies.sqlite -Recurse -Force -EA SilentlyContinue
  18. Remove-Item -path C:\Users\$($_.Name)\AppData\Local\Mozilla\Firefox\Profiles\*.default\webappsstore.sqlite -Recurse -Force -EA SilentlyContinue
  19. Remove-Item -path C:\Users\$($_.Name)\AppData\Local\Mozilla\Firefox\Profiles\*.default\chromeappsstore.sqlite -Recurse -Force -EA SilentlyContinue
  20. }
  21. Write-Host -ForegroundColor yellow "Mozilla caches cleared"
  22. #Write-Host -ForegroundColor Green "SECTION 4: Clearing Google Chrome Caches"
  23. Write-Host -ForegroundColor cyan
  24. Import-CSV -Path C:\users\$env:USERNAME\users.csv -Header Name | foreach {
  25. Remove-Item -path "C:\Users\$($_.Name)\AppData\Local\Google\Chrome\User Data\Default\Cache\*" -Recurse -Force -EA SilentlyContinue
  26. Remove-Item -path "C:\Users\$($_.Name)\AppData\Local\Google\Chrome\User Data\Default\Cache2\entries\*" -Recurse -Force -EA SilentlyContinue
  27. Remove-Item -path "C:\Users\$($_.Name)\AppData\Local\Google\Chrome\User Data\Default\Cookies" -Recurse -Force -EA SilentlyContinue
  28. Remove-Item -path "C:\Users\$($_.Name)\AppData\Local\Google\Chrome\User Data\Default\Media Cache" -Recurse -Force -EA SilentlyContinue
  29. Remove-Item -path "C:\Users\$($_.Name)\AppData\Local\Google\Chrome\User Data\Default\Cookies-Journal" -Recurse -Force -EA SilentlyContinue
  30. # Comment out the following line to remove the Chrome Write Font Cache too.
  31. # Remove-Item -path "C:\Users\$($_.Name)\AppData\Local\Google\Chrome\User Data\Default\ChromeDWriteFontCache" -Recurse -Force -EA SilentlyContinue -Verbose
  32. }
  33. Write-Host -ForegroundColor yellow "Google Chrome caches cleared"
  34. # Clear Internet Explorer
  35. #Write-Host -ForegroundColor Green "SECTION 5: Clearing Internet Explorer Caches"
  36. Write-Host -ForegroundColor cyan
  37. Import-CSV -Path C:\users\$env:USERNAME\users.csv | foreach {
  38. Remove-Item -path "C:\Users\$($_.Name)\AppData\Local\Microsoft\Windows\Temporary Internet Files\*" -Recurse -Force -EA SilentlyContinue
  39. Remove-Item -path "C:\Users\$($_.Name)\AppData\Local\Microsoft\Windows\WER\*" -Recurse -Force -EA SilentlyContinue
  40. Remove-Item -path "C:\Users\$($_.Name)\AppData\Local\Temp\*" -Recurse -Force -EA SilentlyContinue
  41. Remove-Item -path "C:\Windows\Temp\*" -Recurse -Force -EA SilentlyContinue
  42. Remove-Item -path "C:\`$recycle.bin\" -Recurse -Force -EA SilentlyContinue
  43. }
  44. Remove-Item -Path C:\users\$env:USERNAME\users.csv -Force
  45. Write-Host -ForegroundColor yellow "IE caches cleared"
  46. Write-Host -ForegroundColor Green "Nettoyage OK"
  47. } else {
  48. Write-Host -ForegroundColor Yellow "Session Cancelled"
  49. Exit
  50. }