Script for clearing Chrome or Firefox cache on Windows Script for clearing Chrome or Firefox cache on Windows powershell powershell

Script for clearing Chrome or Firefox cache on Windows


In Chrome, you can clear the cache by deleting the contents of the Cache folder in %LocalAppData%\Google\Chrome\User Data\Default\Cache. The history, cookies, and so on are SQLite database files in the parent folder, so you could get rid of them too if you wanted everything gone, like in your example with Internet Explorer:

$Items = @('Archived History',            'Cache\*',            'Cookies',            'History',            'Login Data',            'Top Sites',            'Visited Links',            'Web Data')$Folder = "$($env:LOCALAPPDATA)\Google\Chrome\User Data\Default"$Items | % {     if (Test-Path "$Folder\$_") {        Remove-Item "$Folder\$_"     }}


Here is my variant of cleaning script which contains improved version of Eric's script.It includes Chrome, Chromium and IE directories altogether.
$DaysToDelete variable determines how many days cache data is to be stored on machine.

$DaysToDelete = 1$temporaryIEDir = "C:\users\*\AppData\Local\Microsoft\Windows\Temporary Internet Files\*" ## Remove all files and folders in user's Temporary Internet Files. $cachesDir = "C:\Users\*\AppData\Local\Microsoft\Windows\Caches"  ## Remove all IE caches. $cookiesDir = "C:\Documents and Settings\*\Cookies\*" ## Delets all cookies. $locSetDir = "C:\Documents and Settings\*\Local Settings\Temp\*"  ## Delets all local settings temp $locSetIEDir = "C:\Documents and Settings\*\Local Settings\Temporary Internet Files\*"   ## Delets all local settings IE temp $locSetHisDir = "C:\Documents and Settings\*\Local Settings\History\*"  ## Delets all local settings historyGet-ChildItem $temporaryIEDir, $cachesDir, $cookiesDir, $locSetDir, $locSetIEDir, $locSetHisDir -Recurse -Force -Verbose -ErrorAction SilentlyContinue | Where-Object { ($_.CreationTime -lt $(Get-Date).AddDays(-$DaysToDelete)) } | remove-item -force -Verbose -recurse -ErrorAction SilentlyContinue$DaysToDelete = 7$crLauncherDir = "C:\Documents and Settings\%USERNAME%\Local Settings\Application Data\Chromium\User Data\Default"$chromeDir = "C:\Users\*\AppData\Local\Google\Chrome\User Data\Default"$chromeSetDir = "C:\Users\*\Local Settings\Application Data\Google\Chrome\User Data\Default"$Items = @("*Archived History*", "*Cache*", "*Cookies*", "*History*", "*Login Data*", "*Top Sites*", "*Visited Links*", "*Web Data*")$items | ForEach-Object {$item = $_ Get-ChildItem $crLauncherDir, $chromeDir, $chromeSetDir -Recurse -Force -ErrorAction SilentlyContinue |     Where-Object { ($_.CreationTime -lt $(Get-Date).AddDays(-$DaysToDelete)) -and $_ -like $item} | ForEach-Object -Process { Remove-Item $_ -force -Verbose -recurse -ErrorAction SilentlyContinue }}


Powershell that kills chrome and clean all of chrome's profiles of the user:

taskkill /F /IM "chrome.exe"Start-Sleep -Seconds 5$Items = @('Archived History',            'Cache\*',            'Cookies',            'History',            #'Login Data',            'Top Sites',            'Visited Links'            #'Web Data'            )$Folders = Get-ChildItem "$($env:LOCALAPPDATA)\Google\Chrome\User Data" | ?{ $_.PSIsContainer -and $_.Name -eq "Default" -or $_.Name -like "Profile*"}$Folders | ForEach-Object {    $tmp = $_    $Items | ForEach-Object {         if((Test-Path -Path "$tmp\$_" )){            Remove-Item "$tmp\$_"         }    }}