PowerShell: Change Google Chrome Cache Directory

Lately, I’ve been running a buck load of chrome tabs that utilize all available I/O disk speed that my default C:\ volume could keep up. Thus, Chrome often lags to the point of being annoying or unusable. Here are two methods to move the Default Chrome directory toward a different volume to improve Chrome’s performance:

# Method 1: Move the whole Chrome Default profile's storage directory
$profilePath="C:\Users\$env:username\AppData\Local\Google\Chrome\User Data\Default"

robocopy "$profilePath" "$newPath" /mir /xj /copyall
ren $profilePath "$profilePath`_old"
& mklink $profilePath $newPath /j
cmd /c mklink /d $profilePath $newPath

# Method 2: Move only Chrome Cache
function changeChromeCacheDirectory{
      $defaultCacheDirectory="C:\Users\$env:username\AppData\Local\Google\Chrome\User Data\Default\Cache"
        Stop-Process -Name chrome
        mkdir $newCacheDirectory
        rmdir $defaultCacheDirectory -force -Recurse
        New-Item -ItemType Junction -Path $defaultCacheDirectory -Target $newCacheDirectory
        write-host "Chrome cache directory has been changed`r`nFrom: $defaultCacheDirectory`r`nTo: $newCacheDirectory" -ForegroundColor Green
        return $true
        write-warning $_
        return $false

changeChromeCacheDirectory $newCacheDirectory

Leave a Reply

Your email address will not be published. Required fields are marked *