We are in a Windows AD domain.
We redirect the My Documents folder to a server.
Chrome Enterprise is our default browser.
We can not use roaming profiles.
The Chrome bookmarks need to be stored in the redirected My Documents folder.
We need an up to date copy of the Chrome bookmarks to follow the user when they logon to a new computer.

Our users may logon to several separate computers thought out a day.
They might logon to a computer for the first time, if it is a new placement or a re-images computer.
They might logon to a computer after a long period of time.
They might use the same computer all or most of the time.

To accomplish this I am working on a logon script.
So far the logon script checks to see if a chrome folder exists in the redirected folder.
If the chrome folder is not there, it creates one.
It then checks for a bookmarks file, and if the file does not exist it copies the bookmarks file from the local profile to the redirect My Documents\Chrome folder.
After that it always copies the bookmark file from the redirected My Documents\Chrome folder to the local bookmarks folder.
This is fine until a change is made, because the change happens to the local copy of bookmarks, which will be over written at next login.

I am having problems figuring our how to check which bookmarks file is the “current” file. local or redirected.
I need a way to compare the bookmarks files in the My Documents\Chrome folder and the local folder to see if it is the current copy.
Time stamps is not working. The time stamp does not update then the bookmark files is changed by adding or deleting a URL.
Time created is not working. the oldest or newest is not always the current copy.
Last Write is not working in some situations, because the current copy may not be the latest copy.

I am open to suggestions.
I really appreciate your time and expertise.

This is the existing code:

Logon script

create Chrome folder and bookmark folder if it does not exist.

$user = $env:USERNAME
$MyDoc = [environment]::getfolderpath(“mydocuments”)
if(!(Test-Path -Path “$MyDoc\Chrome”))
{
New-Item -ItemType directory -path $MyDoc\Chrome
}
if(!(Test-Path -Path “$MyDoc\Chrome\bookmarks”))
{
Copy-Item -Path “c:\users$user\Appdata\Local\Google\Chrome\User Data\Default\bookmarks*” -Destination "$MyDoc\Chrome"
exit
}

Logoff Script

Copy changes

$user = $env:USERNAME
$MyDoc = [environment]::getfolderpath(“mydocuments”)

Copy-Item -Path “c:\users$user\Appdata\Local\Google\Chrome\User Data\Default\bookmarks*” -Destination "$MyDoc\Chrome"
exit

6 Spice ups

If you post code, please use the ‘Insert Code’ button. Please and thank you!

192033ab-bb8f-4032-88a5-8e2313af0344-codebutton_small.png

  • Neally Bot

Why not use Chrome admx templates and set up a managed bookmarks folder using GPO?

1 Spice up

I wish that would work for us.

the ADMX template Managed bookmarks does not allow the user to make changes.

Everyone would get the same bookmarks.

It’s not the best solution for our needs.

I wish the ADMX template allow the redirect of only the bookmarks file.

All I could find was redirecting the entire user data folder, and even then chrome warns of stabilization and performance issues.

Are you a 365 or G Suite (or whatever it’s called now) company? You could use the native syncing option (365 would be Edge, but same thing) which should be enforceable by policy. Just trying to think of other options.

1 Spice up

We are not using Office 365 or G-Suite currently. We are using Office 2016. We just wanted Chrome as the default browser, and now need to manage the Chrome bookmark file, if possible.

Anything holding you back from simply using a logon script that overwrites the local copy and a logoff script that overwrites the network copy?

1 Spice up

Hi Mike,

I appreciate the suggestion. Using the logon and logoff method as you describe is the direction we are going currently.

I’ll share the code when we have something that works.

I kept working on this scripting problem until I found the magic sauce.

When using copy-item the files would not over write, not even when I used -force. Eventually I stopped trying to problem solve why and switch to robocopy.

Now both logon and logoff scripts do what I need them to do.

I left in the “code” that I used to assist with problem solving incase some one is curious to see what I did.

I am not the best scripter around, but I was able to get the job done. If anyone has a better way, I invite you to post your solution.

I appreciate all you help comments.


```
# 01/09/2023
# John stinnett
# updated 01/18/2023
#  purpose: copy chrome bookmarks from mydocuments the local computer
#  get the user variables for the logged in user and their my documents
#  then test for the existence of the "Chrome" folder
#  tests for the existence of bookmarks file
#  copy the bookmark file to the chrome folder if there is not one
#  runs at logon
#  uses GPO Chrome - Backup Bookmarks HKEY USERCONFIG\POLICIES\WINDOWS SETTINGS\SCRIPTS(LOGON/LOGOFF)
#  (Computer Configuration -> Policies -> Administrative Templates -> System -> Group Policy). SET TO 1 MINUTE
#  PARAMETER : -Noninteractive -ExecutionPolicy Bypass -Noprofile -file Logon_Bookmarks.ps1 
$user = $env:USERNAME
$MyDoc = [environment]::getfolderpath("mydocuments")
$destinationFile = "$MyDoc\Chrome\Bookmarks"
$currentTime = Get-Date
if(!(Test-Path -Path "$MyDoc\Chrome"))
 {
  New-Item -ItemType directory -path $MyDoc\Chrome
 }
Copy-Item -Path "$MyDoc\Chrome\Bookmarks" -Destination "c:\users\$user\Appdata\Local\Google\Chrome\User Data\Default\"
# Update timestamp of copied file
Set-ItemProperty -Path $destinationFile -Name "LastWriteTime" -Value $currentTime
Exit

```

# 01/09/2023
# John Stinnett
# updated 01/18/2023
#  purpose: backup chrome bookmarks from mydocuments to the local computer
#  get the user variables for the logged in user and their my documents
#  then test for the existence of the "Chrome\bookmarks"
#  copy the bookmark file to the chrome folder if exists
#  runs at logoff
#  uses GPO "Chrome - Backup Bookmarks" HKEY USERCONFIG\POLICIES\WINDOWS SETTINGS\SCRIPTS(LOGON/LOGOFF)
#  (Computer Configuration -> Policies -> Administrative Templates -> System -> Group Policy). SET TO 1 MINUTE
#  PARAMETER : -Noninteractive -ExecutionPolicy Bypass -Noprofile -file Logoff_Bookmarks.ps1
#
# Logoff Script
#
$date = Get-Date 
$user = $env:USERNAME
$MyDoc = [environment]::getfolderpath("mydocuments")
$destinationFile = "$MyDoc\Chrome\Bookmarks"
$localboomarks = "c:\users\$user\Appdata\Local\Google\Chrome\User Data\Default\Bookmarks"
$currentTime = Get-Date
$
# Local folder has the latest version, copy it to My Documents\Chrome folder
# append a date to the Chrome\bookmarks_backup_$(get-date -f yyyy-MM-dd-HH-mm-ss)"
Remove-Item -Path "$MyDoc\Chrome\Bookmarks" -Force -ErrorAction SilentlyContinue
#Copy-Item -Path "c:\users\$user\Appdata\Local\Google\Chrome\User Data\Default\Bookmarks" -Destination "$MyDoc\Chrome\" -Force
#
robocopy $localboomarks $destinationFile /Z /COPY:DAT
#
# Update timestamp of copied file
Set-ItemProperty -Path $destinationFile -Name "LastWriteTime" -Value $currentTime
if(!(Test-Path -Path "$MyDoc\Chrome\log.txt"))
 {
  New-Item -ItemType file -path $MyDoc\Chrome\log.txt
 }
 Add-Content -Path "$MyDoc\Chrome\log.txt" -Value "logoff $date"
exit