iron-from-sf

delete cahce dirs chrome on windows

Aug 1st, 2025 (edited)
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 1.93 KB | Software | 0 0
  1. # Запуск от администратора обязателен
  2.  
  3. # Получаем список всех папок профилей пользователей
  4. $usersPath = "C:\Users"
  5. $chromeRelativePath = "AppData\Local\Google\Chrome\User Data"
  6.  
  7. # Функция для удаления содержимого папки
  8. function Clear-FolderContents($folderPath) {
  9.     if (Test-Path $folderPath) {
  10.         try {
  11.             Get-ChildItem -Path $folderPath -Recurse -Force | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue
  12.             Write-Output "Очищено: $folderPath"
  13.         } catch {
  14.             Write-Warning "Ошибка при удалении содержимого: $folderPath"
  15.         }
  16.     }
  17. }
  18.  
  19. # Обход всех профилей пользователей
  20. Get-ChildItem $usersPath -Directory | ForEach-Object {
  21.     $userProfile = $_.FullName
  22.     $userChromePath = Join-Path $userProfile $chromeRelativePath
  23.  
  24.     if (Test-Path $userChromePath) {
  25.         # Перебор всех профилей Chrome: Profile 1, Default, и т.д.
  26.         Get-ChildItem -Path $userChromePath -Directory | ForEach-Object {
  27.             $profilePath = $_.FullName
  28.             $cachePath = Join-Path $profilePath "Cache"
  29.             $codeCachePath = Join-Path $profilePath "Code Cache"
  30.  
  31.             Clear-FolderContents -folderPath $cachePath
  32.             Clear-FolderContents -folderPath $codeCachePath
  33.         }
  34.     }
  35. }
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42. $users = Get-ChildItem "C:\Users" -Directory
  43.  
  44. foreach ($user in $users) {
  45.     $tempPath = Join-Path $user.FullName "AppData\Local\Temp"
  46.     if (Test-Path $tempPath) {
  47.         try {
  48.             Get-ChildItem $tempPath -Force -Recurse | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
  49.             Write-Output "Очищено: $tempPath"
  50.         } catch {
  51.             Write-Warning "Ошибка при очистке: $($_.Exception.Message)"
  52.         }
  53.     }
  54. }
Tags: chrome cache
Advertisement
Add Comment
Please, Sign In to add comment