Forum Discussion

tsmith92765's avatar
tsmith92765
Copper Contributor
Jan 13, 2023
Solved

Creating a Script to Delete Cookies and Cache of FireFox but if-else statements are not working.

Hello PS Community!   I'm currently in the process of making a script for my company to delete Cookies and Cache of the 3 main browsers we use. Firefox, Chrome, and Edge. My script works perfectly ...
  • Harm_Veenstra's avatar
    Jan 14, 2023

    tsmith92765 I changed your script a little bit:

     

    $FireFox = {
        # Create a User Variable for the ScriptBlock to use #
        $user = (Get-WMIObject -ClassName Win32_ComputerSystem | Select-Object username).username.split("\")[1]
    
        # Remove Cookies from FireFox #
        if (Test-Path C:\Users\$user\AppData\Roaming\Mozilla\Firefox\Profiles\*.default-release\cookies.sqlite) {
            Remove-Item -path C:\Users\$user\AppData\Roaming\Mozilla\Firefox\Profiles\*.default-release\cookies.sqlite -ErrorAction SilentlyContinue
            Write-Host "FireFox Cookies have been found and cleaned."
        }
        else {
            Write-Host "FireFox Cookies not found."
        }
    
        # Remove Cache from Firefox #
        if (Test-Path -path C:\Users\$user\AppData\Local\Mozilla\Firefox\Profiles\*.default-release\cache2) {
            Remove-Item -path C:\Users\$user\AppData\Local\Mozilla\Firefox\Profiles\*.default-release\cache2 -recurse -ErrorAction SilentlyContinue
            Write-Host "Firefox Cache has been found and cleaned."
        }
        else {
            # If no cookies found print a msg #
            Write-Host "FireFox Cache not found."
        }
    }
    
    
    invoke-command -scriptblock $Firefox

     

    This works on my Firefox installation. The first time it cleans, and the second time it can't find the items anymore which is correct. Could you verify this?

Resources