Posted On June 11, 2022

PowerShell: Change Google Chrome Cache Directory

kimconnect 0 comments
blog.KimConnect.com >> Codes >> 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"
$newPath='D:\chrome\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
$newCacheDirectory="D:\chromeCache\$env:username"
function changeChromeCacheDirectory{
    param(
      $newCacheDirectory="D:\chromeCache\$env:username",
      $defaultCacheDirectory="C:\Users\$env:username\AppData\Local\Google\Chrome\User Data\Default\Cache"
    )
    try{
        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
    }catch{
        write-warning $_
        return $false
    }
}

changeChromeCacheDirectory $newCacheDirectory

Leave a Reply

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

Related Post

PowerShell: Get ‘Size on Disk’ of Files in Windows

There are many methods of attempting to obtain "size on disk" values of files in…

Basic CSS: Adjust the Margin of an Element

<style>.injected-text {margin-bottom: -25px;text-align: center;}.box {border-style: solid;border-color: black;border-width: 5px;text-align: center;}.yellow-box {background-color: yellow;padding: 10px;}.red-box {background-color: crimson;color: #fff;padding:…

PowerShell: Obtain Domain Admin Credential

This little snippet is reusable as an appendix to other scripts since Domain Admin access…