Back Up Chrome Browser

Hi Jason,

I have one query, i need to implement one fixlet “Back-up chrome browser.”

**delete __createfile**
**delete "junk_clean.ps1"**
**createfile until EOF**

**$path = "C:\APPBackup\ChromeBackup\Default"**

**if(!(test-path $path))**
**{{ New-Item -ItemType Directory -Force -Path $path }**

**else**
**{{Remove-Item "C:\APPBackup\ChromeBackup\Default\*" -Recurse -Force}**

**if((get-process "chrome" -ea SilentlyContinue) -eq $Null)**

**{{ }**

**else**

**{{Stop-Process -processname "chrome"}**

**Copy-Item -Path "$env:USERPROFILE\appdata\local\Google\Chrome\User Data\Default\*" -Destination "C:\APPBackup\ChromeBackup\Default" -recurse -Force**

**EOF**

**move __createfile "junk_clean.ps1"**
**waithidden { pathname of file ((it as string) of value "Path" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" of native registry) } -ExecutionPolicy Bypass -File junk_clean.ps1**

This action is running on QNA and also on server, however when i am pushing this action through BigFix on desktop/laptop then it is not getting completed.
After pushing this fixlet, backup folder is creating, and chrome process is killing but not copying the files and folders from source to destination.

“COPY command is failing.”

Regards,
Shivani

$env:USERPROFILE is not going to resolve as you expect because the action will be running as LocalSystem, not as the account of a logged-on user.

You’ll need to either change the logic to loop through all of the user profiles instead of relying on $env, or use action overrides to execute the script in the context of a logged-on user instead of LocalSystem. I have some notes on the action overrides settings at Tip - Action Override User settings that may be useful.

(Edit: fixed link)

@JasonWalker, did you mean to put this link as opposed to the 10.0.9 release thread? :wink:

Lol yes thanks

(Forum padding)

Hello,

If you just want to copy the Chrome profile of the logged-on user then Jason’s action overrides solution will accomplish this.

If you want to backup the Chrome profiles for every user on a computer who has one, I have a script for that. I added the destination you specified to the $destination variable.

NOTE: Both your original script and my below script as it currently is will copy only the DEFAULT Chrome profile from Appdata for each user. If there are additional profiles for a Windows user, this script won’t copy it. If you want to copy ALL Chrome profiles, you can edit the script to copy the entire “User Data” folder. Or you can get a little more complicated with the script so it can identify all folders in the “User Data” folder whose contents would indicate it is a profile folder.

$source = "C:\Users"

$destination = "C:\APPBackup\ChromeBackup"

foreach ($userDir in (Get-ChildItem -Path $source -Directory)) {

    $user = $userDir.Name

    $userChromeDir = Join-Path $userDir.FullName "\AppData\Local\Google\Chrome\User Data"

    if (Test-Path -Path $userChromeDir) {

        $userSource = Join-Path $userChromeDir "\Default"

        $userDestination = Join-Path $destination "$user.Chrome_Backup"

        if (!(Test-Path -Path $userDestination -PathType Container)) {

            New-Item -Path $userDestination -ItemType Directory

        }

        Copy-Item -Path $userSource -Destination $userDestination -Recurse -Force

    }

}
1 Like