Backup Chrome/Edge Profile
Powershell Script

I wrote this specifically for when a user is getting a new device and wants their browsers to look and feel exactly how it did previously.

       This process will copy out their entire User Data folder in both chrome and edge and then paste it into a new device.

       This process contains two scripts, a script to save out the profiles and a script to restore them. One runs on old device, one runs on new.

       You can also just do this manually, but this script is nice if you are doing many users at once as you can just point this script at their devices.

Copy/Backup User Data Script:

  1. First you need to set the target directory (preferably a shared directory)
        
      2. Now when you run the script, it will copy out all the user data from both Chrome and Edge to that folder.
                  *Note that you would run this on their original device*
 
      After the files have been moved we will run the next script:
 
 
      1. You need to once again set your source directory (same as your target)
        
      2. Now when you run this script it will fetch the profiles it saved previously and merge them into the currently logged in user’s Appdata
      3. You can navigate to your Appdata > Local > Google > Chrome > User Data to make sure it successfully transferred

 

      NOTE : notice that lines 12 and 13 are commented out, this would be for the off-chance that a user directory has been renamed

 
				
					# THIS IS THE FIRST SCRIPT - COPIES USER DATA
# RUN ON ORIGINAL DEVICE

# Updated 12.24.23 - JL
# This script grabs the Chrome and Edge User Settings for the current logged in user
# It copies them to a target directory (listed below) use a shared location
# This script will forcequit Chrome and Edge

# Define target directory
$targetDirectory = "\\your\\directory\\goes\\here"

# Get current logged-in username (comment out to manually select)
$currentUsername = $env:USERNAME

# Manually select Users\Directory name if it's not autogenerated or is modified
#$currentUsername = "caitlin"

# Source directories
$chromeSource = "C:\Users\$currentUsername\AppData\Local\Google\Chrome\User Data"
$edgeSource = "C:\Users\$currentUsername\AppData\Local\Microsoft\Edge\User Data"

# Destination directories
$userDestination = Join-Path $targetDirectory $currentUsername
$chromeDestination = Join-Path $userDestination "Chrome"
$edgeDestination = Join-Path $userDestination "Edge"

# Terminate Chrome and Edge if they are still running
if (Get-Process -Name chrome -ErrorAction SilentlyContinue) {
    Stop-Process -Name chrome -Force
}
if (Get-Process -Name msedge -ErrorAction SilentlyContinue) {
    Stop-Process -Name msedge -Force
}

# Check if drive exists
if (-not (Test-Path $targetDirectory)) {
    Write-Error "Target directory $targetDirectory not found! Please ensure it is accessible."
    exit
}

# Create directories if they don't exist
if (-not (Test-Path $userDestination)) {
    New-Item -Path $userDestination -ItemType Directory
}
if (-not (Test-Path $chromeDestination)) {
    New-Item -Path $chromeDestination -ItemType Directory
}
if (-not (Test-Path $edgeDestination)) {
    New-Item -Path $edgeDestination -ItemType Directory
}


# Copy Chrome User Data
if (Test-Path $chromeSource) {
    Copy-Item -Path $chromeSource -Destination $chromeDestination -Recurse -Force
} else {
    Write-Warning "Chrome User Data not found for user $currentUsername"
}

# Copy Edge User Data
if (Test-Path $edgeSource) {
    Copy-Item -Path $edgeSource -Destination $edgeDestination -Recurse -Force
} else {
    Write-Warning "Edge User Data not found for user $currentUsername"
}

				
			
				
					# THIS IS THE SECOND SCRIPT - RESTORES USER DATA
# RUN ON NEW DEVICE

# Updated 12.24.23 - JL
# This script prompts the user to close Chrome and Edge.
# It restores Chrome and Edge User Settings for the current logged-in user from a source directory
# This script will forcequit Chrome and Edge.

# Define source directory (from where data is restored)
$sourceDirectory = "\\your\\directory\\goes\\here"

# Get current logged-in username
$currentUsername = $env:USERNAME

# Manually input Users\Directory name below if it's not autogenerated and has been renamed
# Then un-comment the line below
#$currentUsername = "joel"

# Destination directories (to restore the data to)
$chromeDestination = "C:\Users\$currentUsername\AppData\Local\Google\Chrome\User Data"
$edgeDestination = "C:\Users\$currentUsername\AppData\Local\Microsoft\Edge\User Data"

# Source directories (from where the data is copied)
$userSource = Join-Path $sourceDirectory $currentUsername
$chromeSource = Join-Path $userSource "Chrome\User Data"
$edgeSource = Join-Path $userSource "Edge\User Data"

# Terminate Chrome and Edge if they are running
if (Get-Process -Name chrome -ErrorAction SilentlyContinue) {
    Stop-Process -Name chrome -Force
}
if (Get-Process -Name msedge -ErrorAction SilentlyContinue) {
    Stop-Process -Name msedge -Force
}

# Check if source directories exist
if (-not (Test-Path $sourceDirectory)) {
    Write-Error "Source directory $sourceDirectory not found! Please ensure it is accessible."
    exit
}

# Restore Chrome User Data
if (Test-Path $chromeSource) {
    # Copy the CONTENTS of the source User Data folder, not the folder itself
    Copy-Item -Path "$chromeSource\*" -Destination $chromeDestination -Recurse -Force
} else {
    Write-Warning "Backup of Chrome User Data not found for user $currentUsername"
}

# Restore Edge User Data
if (Test-Path $edgeSource) {
    # Copy the CONTENTS of the source User Data folder, not the folder itself
    Copy-Item -Path "$edgeSource\*" -Destination $edgeDestination -Recurse -Force
} else {
    Write-Warning "Backup of Edge User Data not found for user $currentUsername"
}