Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Define the function to clear browser cache
- function Clear-BrowserCache {
- param (
- [string]$Browser,
- [string]$Username = $env:USERNAME
- )
- switch ($Browser) {
- "Chrome" {
- $cachePath = "C:\Users\$Username\AppData\Local\Google\Chrome\User Data"
- if (Test-Path $cachePath) {
- Get-ChildItem -Path "$cachePath" | Where-Object { $_.PSIsContainer } | ForEach-Object {
- Remove-Item -Path "$($_.FullName)\Cache" -Recurse -Force
- Remove-Item -Path "$($_.FullName)\Cookies" -Recurse -Force
- # Add more items as needed (e.g., History)
- }
- }
- }
- "Firefox" {
- $profileDir = "C:\Users\$Username\AppData\Local\Mozilla\Firefox\Profiles"
- if (Test-Path $profileDir) {
- Get-ChildItem -Directory "$profileDir" | ForEach-Object {
- Remove-Item -Path "$($_.FullName)\cache2\"*.*" # Note: Firefox uses 'cache2' directory for newer versions.
- }
- }
- }
- }
- Write-Host "Cache cleared for user '$Username' in browser '$Browser'."
- }
- # Example usage:
- foreach ($user in (Get-WmiObject Win32_UserProfile).Localpathname.Split("\")[2]) {
- Clear-BrowserCache "Chrome" $user
- Clear-BrowserCache "Firefox" $user
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement