Menghapus Cache Google
Akhir-akhir ini saya kesal karena laptop yang kugunakan tinggal sedikit ruang penyimpanan. Salah satu tersangkanya adalah Google. Masalahnya, saya banyak menggunakan profile Google dan saya agak khawatir jika saya delete maka saya harus login lagi.
Jadi saya meminta ChatGPT untuk membuat skrip Powershell 5.1 untuk menghapus Cache google untuk setiap profile.
$base = "$env:LOCALAPPDATA\Google\Chrome\User Data"
Write-Host "=== Scanning Chrome profiles in $base ===`n"
# Dapatkan semua folder profil
$profiles = Get-ChildItem $base -Directory | Where-Object { $_.Name -match '^Profile' -or $_.Name -eq 'Default' -or $_.Name -eq 'Guest Profile' }
foreach ($p in $profiles) {
$profilePath = $p.FullName
$prefFile = Join-Path $profilePath "Preferences"
$profileName = $p.Name
$googleAccount = "(unknown)"
# Coba ambil nama akun Google dari file Preferences
if (Test-Path $prefFile) {
try {
$json = Get-Content $prefFile -Raw | ConvertFrom-Json -ErrorAction Stop
if ($json.account_info) {
$googleAccount = ($json.account_info | Select-Object -First 1).email
} elseif ($json.profile.name) {
$googleAccount = $json.profile.name
}
} catch {
$googleAccount = "(failed to parse)"
}
}
Write-Host " Profile: $profileName ($googleAccount)"
# Hitung ukuran sebelum
try {
$before = (Get-ChildItem $profilePath -Recurse -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum / 1MB
} catch { $before = 0 }
# Hapus folder cache umum di setiap profil
$targets = @(
"Cache", "Code Cache", "GPUCache", "Service Worker",
"Media Cache", "File System", "DawnCache", "DawnGraphiteCache", "DawnWebGPUCache","IndexedDB"
)
foreach ($t in $targets) {
$targetPath = Join-Path $profilePath $t
if (Test-Path $targetPath) {
Remove-Item $targetPath -Recurse -Force -ErrorAction SilentlyContinue
}
}
# Hitung ukuran sesudah
try {
$after = (Get-ChildItem $profilePath -Recurse -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum / 1MB
} catch { $after = 0 }
Write-Host (" Size before: {0:N1} MB → after: {1:N1} MB" -f $before, $after)
Write-Host ""
}
Write-Host "=== Cleaning global Chrome cache outside profiles... ===`n"
# Folder cache global di luar profil
$globalTargets = @(
"component_crx_cache",
"extensions_crx_cache",
"GrShaderCache",
"ShaderCache",
"Safe Browsing",
"Snapshots",
"System Profile"
)
foreach ($g in $globalTargets) {
$path = Join-Path $base $g
if (Test-Path $path) {
Write-Host " Removing $g"
Remove-Item $path -Recurse -Force -ErrorAction SilentlyContinue
}
}
Write-Host "`n All Chrome profiles and global caches cleaned!"
0 comments:
Post a Comment