Category filter
Script to clear browser cache on Windows devices
A browser cache is a database of files that stores resources such as texts, images, and other media from websites. This reduces the time required to load previously visited websites by avoiding the need to download the same data from the internet. However, browsers may load the previous version of websites even if the website is updated due to the cache present on the device. Also, caches can accumulate over time and consume storage space on the device. Hence, enterprises may require to clear the browser’s cache from the devices to save space and load newly updated websites without any issues. You can remotely deploy scripts from the Hexnode portal to clear the browser’s cache from the Windows devices.
Clear cache on Google Chrome
PowerShell script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
param([string] $username="") if(Test-Path -Path C:\Users\$username\AppData\Local\Google\Chrome\User` Data\Default\Cache) { $itemsCountBefore = Get-ChildItem -Path C:\Users\$username\AppData\Local\Google\Chrome\User` Data\Default\Cache -Recurse | Measure-Object | %{$_.Count} Remove-Item -Path C:\Users\$username\AppData\Local\Google\Chrome\User` Data\Default\Cache -Recurse -Force $itemsCountAfter = Get-ChildItem -Path C:\Users\$username\AppData\Local\Google\Chrome\User` Data\Default\Cache -Recurse | Measure-Object | %{$_.Count} if($itemsCountBefore -gt $itemsCountAfter) { Write-host "Cache cleared for Google Chrome" } else { Write-Host "Failed to clear cache for Google Chrome" } } else { Write-host "Specified path doesn't exist." } |
Provide the target username as an argument. If the cache has already been cleared, the error “Specified path doesn’t exist.” will be displayed.
Batch script
1 |
del /q /s /f “C:\Users\<Username>\AppData\Local\Google\Chrome\User Data\Default\Cache” |
Replace <Username>
with the username of the user account from which the Google Chrome browser cache needs to be cleared. If the cache has already been cleared, executing the command may return an error.
Clear cache on Mozilla Firefox
PowerShell script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
param([string] $username="") if(Test-Path -Path C:\Users\$username\AppData\Local\Mozilla\Firefox\Profiles\*\cache2\entries) { $itemsCountBefore = Get-ChildItem -Path C:\Users\$username\AppData\Local\Mozilla\Firefox\Profiles\*\cache2\entries -Recurse | Measure-Object | %{$_.Count} Remove-Item -Path C:\Users\$username\AppData\Local\Mozilla\Firefox\Profiles\*\cache2\entries -Recurse -Force $itemsCountAfter = Get-ChildItem -Path C:\Users\$username\AppData\Local\Mozilla\Firefox\Profiles\*\cache2\entries -Recurse | Measure-Object | %{$_.Count} if($itemsCountBefore -gt $itemsCountAfter) { Write-host "Cache cleared for Mozilla Firefox" } else { Write-Host "Failed to clear cache for Mozilla Firefox" } } else { Write-host "Specified path doesn't exist." } |
Batch script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
@echo off set DataDir=C:\Users\%USERNAME%\AppData\Local\Mozilla\Firefox\Profiles del /q /s /f "%DataDir%" rd /s /q "%DataDir%" for /d %%x in (C:\Users\<username>\AppData\Roaming\Mozilla\Firefox\Profiles\*) do del /q /s /f %%x\*sqlite |
Replace <Username>
with the username of the user account from which the Firefox browser cache needs to be cleared. If the cache has already been cleared, executing the command may return an error.
Clear cache on Microsoft Edge
PowerShell script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
param([string] $username="") if(Test-Path -Path C:\Users\$username\AppData\Local\Microsoft\Edge\User` Data\Default\Cache) { $itemsCountBefore = Get-ChildItem -Path C:\Users\$username\AppData\Local\Microsoft\Edge\User` Data\Default\Cache -Recurse | Measure-Object | %{$_.Count} Remove-Item -Path C:\Users\$username\AppData\Local\Microsoft\Edge\User` Data\Default\Cache -Recurse -Force $itemsCountAfter = Get-ChildItem -Path C:\Users\$username\AppData\Local\Microsoft\Edge\User` Data\Default\Cache -Recurse | Measure-Object | %{$_.Count} if($itemsCountBefore -gt $itemsCountAfter) { Write-host "Cache cleared for Microsoft Edge" } else { Write-Host "Failed to clear cache for Microsoft Edge" } } else { Write-host "Specified path doesn't exist." } |
The PowerShell scripts use the $username
parameter to construct the path to the Chrome, Edge or Firefox cache folder, which includes the name of the user profile directory.
Get-ChildItem
is used to fetch count of items in the cache directory before and after clearing the cache.