Cleanup All User Chrome Cache

This script will clean all Chrome cache for all users on a Windows 7 or newer system.

# Define the base directory for user profiles
$usersPath = "C:\Users"
$totalBeforeCleanup = 0
$totalAfterCleanup = 0

# Loop through each user folder in the Users directory
Get-ChildItem -Path $usersPath -Directory | ForEach-Object {
$chromeCachePath = Join-Path -Path $_.FullName -ChildPath "AppData\Local\Google\Chrome\User Data\Default\Cache"
$userBeforeSize = 0
$userAfterSize = 0

# Check if the Chrome Cache folder exists
if (Test-Path -Path $chromeCachePath) {
# Calculate size before cleanup
$userBeforeSize = (Get-ChildItem -Path $chromeCachePath -Recurse -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum / 1MB
$totalBeforeCleanup += $userBeforeSize

# Remove all files in the Chrome Cache folder
Get-ChildItem -Path $chromeCachePath -Recurse -Force -ErrorAction SilentlyContinue | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue

# Calculate size after cleanup (to check if any files were in use and not deleted)
$userAfterSize = (Get-ChildItem -Path $chromeCachePath -Recurse -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum / 1MB
$totalAfterCleanup += $userAfterSize

# Output results for each user
Write-Output ("User: {0}`nCache size before cleanup: {1:N2} MB`nCache size after cleanup: {2:N2} MB`nFreed up: {3:N2} MB" -f $_.Name, $userBeforeSize, $userAfterSize, ($userBeforeSize - $userAfterSize))
} else {
Write-Output "No Chrome cache folder found for user: $($_.Name)"
}
}

# Output total cleanup summary
$totalCleanedUp = $totalBeforeCleanup - $totalAfterCleanup
Write-Output ("`nTotal Chrome cache size before cleanup: {0:N2} MB" -f $totalBeforeCleanup)
Write-Output ("Total Chrome cache size after cleanup: {0:N2} MB" -f $totalAfterCleanup)
Write-Output ("Total freed up: {0:N2} MB" -f $totalCleanedUp)

Cleanup Windows User Temporary Files

This script will cleanup all users temporary files in their AppData\Local\Temp for Windows 7 and newer.

# Define the base directory for user profiles
$usersPath = "C:\Users"
$totalBeforeCleanup = 0
$totalAfterCleanup = 0

# Loop through each user folder in the Users directory
Get-ChildItem -Path $usersPath -Directory | ForEach-Object {
$userTempPath = Join-Path -Path $_.FullName -ChildPath "AppData\Local\Temp"
$userBeforeSize = 0
$userAfterSize = 0

# Check if the Temp folder exists
if (Test-Path -Path $userTempPath) {
# Calculate size before cleanup
$userBeforeSize = (Get-ChildItem -Path $userTempPath -Recurse -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum / 1MB
$totalBeforeCleanup += $userBeforeSize

# Remove all files in the Temp folder
Get-ChildItem -Path $userTempPath -Recurse -Force -ErrorAction SilentlyContinue | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue

# Calculate size after cleanup (to check if any files were in use and not deleted)
$userAfterSize = (Get-ChildItem -Path $userTempPath -Recurse -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum / 1MB
$totalAfterCleanup += $userAfterSize

# Output results for each user
Write-Output ("User: {0}`nSize before cleanup: {1:N2} MB`nSize after cleanup: {2:N2} MB`nCleaned up: {3:N2} MB" -f $_.Name, $userBeforeSize, $userAfterSize, ($userBeforeSize - $userAfterSize))
} else {
Write-Output "No Temp folder found for user: $($_.Name)"
}
}

# Output total cleanup summary
$totalCleanedUp = $totalBeforeCleanup - $totalAfterCleanup
Write-Output ("`nTotal size before cleanup: {0:N2} MB" -f $totalBeforeCleanup)
Write-Output ("Total size after cleanup: {0:N2} MB" -f $totalAfterCleanup)
Write-Output ("Total cleaned up: {0:N2} MB" -f $totalCleanedUp)

Cleanup Service Pack Backup Files to Reclaim Space

Came across a nice tip when I was researching an unrelated problem today. I discovered that I could use dism to cleanup Vista/7/2008 Service Pack install backup files to reclaim space!

Warning!

The service pack can’t be uninstalled after this operation is completed. This operation will remove backup files created during service pack installation. Use /hidesp switch to hide the service pack from Installed Updates.
 

dism /online /cleanup-image /spsuperseded

It took about 45 minutes to run on a Server 2008 R2 SP1 system I have in a virtual lab with 2vCPU and 2GB RAM. YMMV.

Batch File to Cleanup Windows 2000, XP and Server 2003 User Profiles, Temp Folders, Internet Explorer Temporary Files

I’ve had this around for the longest time and figured I better put it here before I lose it forever to the dying Microsoft releases.

Note: This also cleans up VMware temporary files which build up over time. See this post for more information:  VMware Tray Dump Files Chewing up Space

Update: Added line to remove Temporary Internet Files directory/subdirectories also.

@echo off
setlocal
@for /d %%d in ( C:\Documents and Settings\* ) do @(
  echo %%d
  if exist %%d\Application Data\VMware (
    del /q %%d\Application Data\VMware\*.*
  )
  if exist %%d\Local Settings (
    if exist %%d\Local Settings\Temp (
      for /d %%e in ( %%d\Local Settings\Temp\* ) do @(
        attrib -R -A -S -H %%e\*.*
        rmdir %%e /s /q
      )
      if exist %%d\Local Settings\Temporary Internet Files (
        rmdir %%d\Local Settings\Temporary Internet Files /s /q
      )
      if exist %%d\Local Settings\Temp\*.* (
        attrib -R -A -S -H %%d\Local Settings\Temp\*.*
        del %%d\Local Settings\Temp\*.* /q
      )
    )
  )
)

Cleanup All Users' Temporary Files

This script simply cleans up all users’ temporary files and temporary internet files.
This works on Windows XP, Windows Server 2003.

@echo off
setlocal
@for /d %%d in ( "C:\Documents and Settings\*" ) do @(
echo %%d
if exist "%%d\Local Settings" (
if exist "%%d\Local Settings\Temp" (
for /d %%e in ( "%%d\Local Settings\Temp\*" ) do @(
attrib -R -A -S -H "%%e*.*"
rmdir "%%e" /s /q
)
if exist "%%d\Local Settings\Temp\*.*" (
attrib -R -A -S -H "%%d\Local Settings\Temp\*.*"
del "%%d\Local Settings\Temp\*.*" /q
)
)
)
)