We are in a Windows AD domain.
\nWe redirect the My Documents folder to a server.
\nChrome Enterprise is our default browser.
\nWe can not use roaming profiles.
\nThe Chrome bookmarks need to be stored in the redirected My Documents folder.
\nWe need an up to date copy of the Chrome bookmarks to follow the user when they logon to a new computer.<\/p>\n
Our users may logon to several separate computers thought out a day.
\nThey might logon to a computer for the first time, if it is a new placement or a re-images computer.
\nThey might logon to a computer after a long period of time.
\nThey might use the same computer all or most of the time.<\/p>\n
To accomplish this I am working on a logon script.
\nSo far the logon script checks to see if a chrome folder exists in the redirected folder.
\nIf the chrome folder is not there, it creates one.
\nIt 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.
\nAfter that it always copies the bookmark file from the redirected My Documents\\Chrome folder to the local bookmarks folder.
\nThis 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.<\/p>\n
I am having problems figuring our how to check which bookmarks file is the “current” file. local or redirected.
\nI 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.
\nTime stamps is not working. The time stamp does not update then the bookmark files is changed by adding or deleting a URL.
\nTime created is not working. the oldest or newest is not always the current copy.
\nLast Write is not working in some situations, because the current copy may not be the latest copy.<\/p>\n
I am open to suggestions.
\nI really appreciate your time and expertise.<\/p>\n
This is the existing code:<\/p>\n
$user = $env:USERNAME
\n$MyDoc = [environment]::getfolderpath(“mydocuments”)
\nif(!(Test-Path -Path “$MyDoc\\Chrome”))
\n{
\nNew-Item -ItemType directory -path $MyDoc\\Chrome
\n}
\nif(!(Test-Path -Path “$MyDoc\\Chrome\\bookmarks”))
\n{
\nCopy-Item -Path “c:\\users$user\\Appdata\\Local\\Google\\Chrome\\User Data\\Default\\bookmarks*” -Destination \"$MyDoc\\Chrome\"
\nexit
\n}<\/p>\n
$user = $env:USERNAME
\n$MyDoc = [environment]::getfolderpath(“mydocuments”)<\/p>\n
Copy-Item -Path “c:\\users$user\\Appdata\\Local\\Google\\Chrome\\User Data\\Default\\bookmarks*” -Destination \"$MyDoc\\Chrome\"
\nexit<\/p>","upvoteCount":6,"answerCount":9,"datePublished":"2023-01-13T16:58:42.000Z","author":{"@type":"Person","name":"john3504","url":"https://community.spiceworks.com/u/john3504"},"acceptedAnswer":{"@type":"Answer","text":"
I kept working on this scripting problem until I found the magic sauce.<\/p>\n
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.<\/p>\n
Now both logon and logoff scripts do what I need them to do.<\/p>\n
I left in the “code” that I used to assist with problem solving incase some one is curious to see what I did.<\/p>\n
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.<\/p>\n
I appreciate all you help comments.<\/p>\n
\n```\n# 01/09/2023\n# John stinnett\n# updated 01/18/2023\n# purpose: copy chrome bookmarks from mydocuments the local computer\n# get the user variables for the logged in user and their my documents\n# then test for the existence of the \"Chrome\" folder\n# tests for the existence of bookmarks file\n# copy the bookmark file to the chrome folder if there is not one\n# runs at logon\n# uses GPO Chrome - Backup Bookmarks HKEY USERCONFIG\\POLICIES\\WINDOWS SETTINGS\\SCRIPTS(LOGON/LOGOFF)\n# (Computer Configuration -> Policies -> Administrative Templates -> System -> Group Policy). SET TO 1 MINUTE\n# PARAMETER : -Noninteractive -ExecutionPolicy Bypass -Noprofile -file Logon_Bookmarks.ps1 \n$user = $env:USERNAME\n$MyDoc = [environment]::getfolderpath(\"mydocuments\")\n$destinationFile = \"$MyDoc\\Chrome\\Bookmarks\"\n$currentTime = Get-Date\nif(!(Test-Path -Path \"$MyDoc\\Chrome\"))\n {\n New-Item -ItemType directory -path $MyDoc\\Chrome\n }\nCopy-Item -Path \"$MyDoc\\Chrome\\Bookmarks\" -Destination \"c:\\users\\$user\\Appdata\\Local\\Google\\Chrome\\User Data\\Default\\\"\n# Update timestamp of copied file\nSet-ItemProperty -Path $destinationFile -Name \"LastWriteTime\" -Value $currentTime\nExit\n\n```\n\n# 01/09/2023\n# John Stinnett\n# updated 01/18/2023\n# purpose: backup chrome bookmarks from mydocuments to the local computer\n# get the user variables for the logged in user and their my documents\n# then test for the existence of the \"Chrome\\bookmarks\"\n# copy the bookmark file to the chrome folder if exists\n# runs at logoff\n# uses GPO \"Chrome - Backup Bookmarks\" HKEY USERCONFIG\\POLICIES\\WINDOWS SETTINGS\\SCRIPTS(LOGON/LOGOFF)\n# (Computer Configuration -> Policies -> Administrative Templates -> System -> Group Policy). SET TO 1 MINUTE\n# PARAMETER : -Noninteractive -ExecutionPolicy Bypass -Noprofile -file Logoff_Bookmarks.ps1\n#\n# Logoff Script\n#\n$date = Get-Date \n$user = $env:USERNAME\n$MyDoc = [environment]::getfolderpath(\"mydocuments\")\n$destinationFile = \"$MyDoc\\Chrome\\Bookmarks\"\n$localboomarks = \"c:\\users\\$user\\Appdata\\Local\\Google\\Chrome\\User Data\\Default\\Bookmarks\"\n$currentTime = Get-Date\n$\n# Local folder has the latest version, copy it to My Documents\\Chrome folder\n# append a date to the Chrome\\bookmarks_backup_$(get-date -f yyyy-MM-dd-HH-mm-ss)\"\nRemove-Item -Path \"$MyDoc\\Chrome\\Bookmarks\" -Force -ErrorAction SilentlyContinue\n#Copy-Item -Path \"c:\\users\\$user\\Appdata\\Local\\Google\\Chrome\\User Data\\Default\\Bookmarks\" -Destination \"$MyDoc\\Chrome\\\" -Force\n#\nrobocopy $localboomarks $destinationFile /Z /COPY:DAT\n#\n# Update timestamp of copied file\nSet-ItemProperty -Path $destinationFile -Name \"LastWriteTime\" -Value $currentTime\nif(!(Test-Path -Path \"$MyDoc\\Chrome\\log.txt\"))\n {\n New-Item -ItemType file -path $MyDoc\\Chrome\\log.txt\n }\n Add-Content -Path \"$MyDoc\\Chrome\\log.txt\" -Value \"logoff $date\"\nexit\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2023-01-20T14:09:58.000Z","url":"https://community.spiceworks.com/t/logon-script-to-update-bookmarks/944069/9","author":{"@type":"Person","name":"john3504","url":"https://community.spiceworks.com/u/john3504"}},"suggestedAnswer":[{"@type":"Answer","text":"We are in a Windows AD domain.
\nWe redirect the My Documents folder to a server.
\nChrome Enterprise is our default browser.
\nWe can not use roaming profiles.
\nThe Chrome bookmarks need to be stored in the redirected My Documents folder.
\nWe need an up to date copy of the Chrome bookmarks to follow the user when they logon to a new computer.<\/p>\n
Our users may logon to several separate computers thought out a day.
\nThey might logon to a computer for the first time, if it is a new placement or a re-images computer.
\nThey might logon to a computer after a long period of time.
\nThey might use the same computer all or most of the time.<\/p>\n
To accomplish this I am working on a logon script.
\nSo far the logon script checks to see if a chrome folder exists in the redirected folder.
\nIf the chrome folder is not there, it creates one.
\nIt 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.
\nAfter that it always copies the bookmark file from the redirected My Documents\\Chrome folder to the local bookmarks folder.
\nThis 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.<\/p>\n
I am having problems figuring our how to check which bookmarks file is the “current” file. local or redirected.
\nI 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.
\nTime stamps is not working. The time stamp does not update then the bookmark files is changed by adding or deleting a URL.
\nTime created is not working. the oldest or newest is not always the current copy.
\nLast Write is not working in some situations, because the current copy may not be the latest copy.<\/p>\n
I am open to suggestions.
\nI really appreciate your time and expertise.<\/p>\n
This is the existing code:<\/p>\n
<\/a>Logon script<\/h1>\n<\/a>create Chrome folder and bookmark folder if it does not exist.<\/h1>\n$user = $env:USERNAME
\n$MyDoc = [environment]::getfolderpath(“mydocuments”)
\nif(!(Test-Path -Path “$MyDoc\\Chrome”))
\n{
\nNew-Item -ItemType directory -path $MyDoc\\Chrome
\n}
\nif(!(Test-Path -Path “$MyDoc\\Chrome\\bookmarks”))
\n{
\nCopy-Item -Path “c:\\users$user\\Appdata\\Local\\Google\\Chrome\\User Data\\Default\\bookmarks*” -Destination \"$MyDoc\\Chrome\"
\nexit
\n}<\/p>\n
<\/a>Logoff Script<\/h1>\n<\/a>Copy changes<\/h1>\n$user = $env:USERNAME
\n$MyDoc = [environment]::getfolderpath(“mydocuments”)<\/p>\n
<\/a><\/h1>\nCopy-Item -Path “c:\\users$user\\Appdata\\Local\\Google\\Chrome\\User Data\\Default\\bookmarks*” -Destination \"$MyDoc\\Chrome\"
\nexit<\/p>","upvoteCount":6,"datePublished":"2023-01-13T16:58:42.000Z","url":"https://community.spiceworks.com/t/logon-script-to-update-bookmarks/944069/1","author":{"@type":"Person","name":"john3504","url":"https://community.spiceworks.com/u/john3504"}},{"@type":"Answer","text":"
If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>\n