PowerShell: Change Google Chrome Cache Directory

$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 *