Advertisement
iron-from-sf

clear-br-cache

Feb 18th, 2025
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Define the function to clear browser cache
  2. function Clear-BrowserCache {
  3.     param (
  4.         [string]$Browser,
  5.         [string]$Username = $env:USERNAME
  6.     )
  7.  
  8.     switch ($Browser) {
  9.         "Chrome" {
  10.             $cachePath = "C:\Users\$Username\AppData\Local\Google\Chrome\User Data"
  11.             if (Test-Path $cachePath) {
  12.                 Get-ChildItem -Path "$cachePath" | Where-Object { $_.PSIsContainer } | ForEach-Object {
  13.                     Remove-Item -Path "$($_.FullName)\Cache" -Recurse -Force
  14.                     Remove-Item -Path "$($_.FullName)\Cookies" -Recurse -Force
  15.                     # Add more items as needed (e.g., History)
  16.                 }
  17.             }
  18.         }
  19.         "Firefox" {
  20.             $profileDir = "C:\Users\$Username\AppData\Local\Mozilla\Firefox\Profiles"
  21.             if (Test-Path $profileDir) {
  22.                 Get-ChildItem -Directory "$profileDir" | ForEach-Object {
  23.                     Remove-Item -Path "$($_.FullName)\cache2\"*.*" # Note: Firefox uses 'cache2' directory for newer versions.
  24.                }
  25.            }
  26.        }
  27.    }
  28.  
  29.    Write-Host "Cache cleared for user '$Username' in browser '$Browser'."
  30. }
  31.  
  32. # Example usage:
  33. foreach ($user in (Get-WmiObject Win32_UserProfile).Localpathname.Split("\")[2]) {
  34.    Clear-BrowserCache "Chrome" $user
  35.    Clear-BrowserCache "Firefox" $user
  36. }
  37.  
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement