Kaseya Community

Procedure is not running a powershell script properly

  • Hello everyone. I am trying to run a procedure to clear the cache and cookies from an Active Chrome session. I found a PowerShell script online that works fine if ran manually but when added to a procedure, it will not clear anything. I have tried all of the Statements available for PowerShell but none of them seem to work. Any Ideas? Below is the script;

    Remove-Item -path "$env:LOCALAPPDATA\Google\Chrome\User Data\Default\Cache\*" -Recurse -Force -EA SilentlyContinue
    Remove-Item -path "$env:LOCALAPPDATA\Google\Chrome\User Data\Default\Cache2\entries\*" -Recurse -Force -EA SilentlyContinue
    Remove-Item -path "$env:LOCALAPPDATA\Google\Chrome\User Data\Default\Cookies" -Recurse -Force -EA SilentlyContinue
    Remove-Item -path "$env:LOCALAPPDATA\Google\Chrome\User Data\Default\Media Cache" -Recurse -Force -EA SilentlyContinue
    Remove-Item -path "$env:LOCALAPPDATA\Google\Chrome\User Data\Default\Cookies-Journal" -Recurse -Force -EA SilentlyContinue

    I looked at the logs but was not able to pinpoint the source. I get the following descriptions after I attempt the procedure.

    Powershell is present.

    Powershell command specified as (path).

    No command variable detected.

    Not sending output to variable.

    Executing command as System (filepath)

    Powershell command completed!

    Script Summary: Success THEN.

    Any help would be appreciated. Thanks!

  • Make a step to:

    executeShellCommandToVariable (as user)

    command to run: echo %LOCALAPPDATA%

    This should then allow you to run these commands as system or user:

    Remove-Item -path "#global:cmdresults#\Google\Chrome\User Data\Default\Cache\*" -Recurse -Force -EA SilentlyContinue

    Remove-Item -path "#global:cmdresults#\Google\Chrome\User Data\Default\Cache2\entries\*" -Recurse -Force -EA SilentlyContinue

    Remove-Item -path "#global:cmdresults#\Google\Chrome\User Data\Default\Cookies" -Recurse -Force -EA SilentlyContinue

    Remove-Item -path "#global:cmdresults#\Google\Chrome\User Data\Default\Media Cache" -Recurse -Force -EA SilentlyContinue

    Remove-Item -path "#global:cmdresults#\Google\Chrome\User Data\Default\Cookies-Journal" -Recurse -Force -EA SilentlyContinue

  • Thank you for your response. I followed your instructions but I still cannot get the files to be removed. I updated my ps1 file to adjust the new prefix above and I checked the logs and received the same messages with the exception of one.

    Executing command in standard shell as user: echo %LOCALAPPDATA% >"c:\kworking\commandresults-1496174160.txt" 2>&1

    This was the message immediately after I the message stating the command was ran.

    For reference I used the following lines.

    Getvariable -specified the C drive

    writefile - placed the ps1 file to the temp folder

    executeshellcommandtovariable - ran the command you requested above

    executespowerhellcommand64bitsystem - inserted the filepath to the ps1 file.