Skip to content
KBHost
Menu
216.73.216.188
KBHost
FileHost
Home
/
Knowledgebase
/
Snippets
/
Windows
/
Clear Chrome and Edge Cache
Clear Chrome and Edge Cache
0
0
# Script to clear Chrome and Edge browser caches for all user profiles # Get all user profile directories, excluding system accounts $users = Get-ChildItem 'C:\Users' -Directory | Where-Object { $_.Name -notin @('Public', 'Default', 'Default User', 'All Users') } # Track statistics for reporting $totalClearedSize = 0 $processedUsers = 0 # Force close all browser instances Write-Host "Closing browser processes..." -ForegroundColor Yellow $browserProcesses = @("chrome", "msedge") foreach ($process in $browserProcesses) { if (Get-Process -Name $process -ErrorAction SilentlyContinue) { Stop-Process -Name $process -Force -ErrorAction SilentlyContinue Write-Host " Closed all $process processes" -ForegroundColor Yellow # Give browsers time to fully close Start-Sleep -Seconds 2 } } foreach ($user in $users) { $userName = $user.Name $processedUsers++ Write-Host "Processing user: $userName..." -ForegroundColor Cyan # Define browser paths in a structured way for better maintainability $browserPaths = @{ Chrome = @{ MainCache = Join-Path $user.FullName 'AppData\Local\Google\Chrome\User Data\Default\Cache' SWCache = Join-Path $user.FullName 'AppData\Local\Google\Chrome\User Data\Default\Service Worker\CacheStorage' Network = Join-Path $user.FullName 'AppData\Local\Google\Chrome\User Data\Default\Network' GPUCache = Join-Path $user.FullName 'AppData\Local\Google\Chrome\User Data\Default\GPUCache' } Edge = @{ MainCache = Join-Path $user.FullName 'AppData\Local\Microsoft\Edge\User Data\Default\Cache' SWCache = Join-Path $user.FullName 'AppData\Local\Microsoft\Edge\User Data\Default\Service Worker\CacheStorage' Network = Join-Path $user.FullName 'AppData\Local\Microsoft\Edge\User Data\Default\Network' GPUCache = Join-Path $user.FullName 'AppData\Local\Microsoft\Edge\User Data\Default\GPUCache' } } # Process each browser's cache locations foreach ($browser in $browserPaths.Keys) { $cacheLocations = $browserPaths[$browser] foreach ($cacheType in $cacheLocations.Keys) { $path = $cacheLocations[$cacheType] if (Test-Path $path) { # Get size before cleanup for reporting $sizeBefore = (Get-ChildItem $path -Recurse -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum if ($null -eq $sizeBefore) { $sizeBefore = 0 } # Clear the cache Remove-Item -Path "$path\*" -Recurse -Force -ErrorAction SilentlyContinue # Calculate freed space $clearedSize = $sizeBefore / 1MB $totalClearedSize += $clearedSize Write-Host " Cleared $browser $cacheType cache: $([math]::Round($clearedSize, 2)) MB" -ForegroundColor Green } } } Write-Host "Completed processing user: $userName" -ForegroundColor Cyan Write-Host "-----------------------------------------" } # Summary report Write-Host "Cache Cleanup Summary:" -ForegroundColor Magenta Write-Host "Users processed: $processedUsers" -ForegroundColor Magenta Write-Host "Total space cleared: $([math]::Round($totalClearedSize, 2)) MB" -ForegroundColor Magenta
No sleep -
00:00
Password Generator
Most viewed
Connect to Office 365 with PowerShell
Silent update Microsoft Remote Desktop
Add Microsoft Photos app to Server 2019
Enable NFS client in Windows 10
Clear Outlook filter for all folders
Asus ZenWiFi LED color status
Ventoy Windows 11 To Go
Find and delete all snapshots
Most recent
Install or Update reMarkable
TrueNAS Clear failed jobs history
TrueNAS SSH Hetzner Storage Box Rsync
Print Screen from PowerShell
Create local user during Windows Setup
Force Microsoft 365 installation
Enable MailTips in Microsoft 365
Get Home Assistant Logs
We use cookies to ensure the best experience on our website. If you continue to use this site, we assume that you are happy with this.
Ok