# Script to add bookmarks to Chrome

**URL:** <https://forums.powershell.org/t/script-to-add-bookmarks-to-chrome/18567>\
**Category:** PowerShell Help\
**Created:** [February 13, 2022, 7:02am UTC](https://forums.powershell.org/t/script-to-add-bookmarks-to-chrome/18567 "2022-02-13T07:02:52Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![PatM](https://avatars.discourse-cdn.com/v4/letter/p/9d8465/32.png) [@PatM](https://forums.powershell.org/u/PatM)\
**Post date:** [February 13, 2022, 7:02am UTC](https://forums.powershell.org/t/script-to-add-bookmarks-to-chrome/18567/1 "2022-02-13T07:02:52Z")

</div>

I am new to Powershell. I want to create a script _ **to add specific bookmarks to a user’s Chrome browser** _ when setting up their account with them. I would put it on a USB drive and share it with my team.

I have found a script that does this and created an EXE with it but I need to know how to add not just one bookmark but multiple. I can see somewhat is going on with the script but I’m not familiar enough to understand enough to add more to the script to add multiple bookmarks.

```auto
$fileBookmarks="$env:LOCALAPPDATA\Google\Chrome\User Data\Default\Bookmarks"
$dataBookmarks=Get-Content $fileBookmarks -Encoding UTF8| Out-String |ConvertFrom-Json
function createNewChromeBookmark ($Bookmarks, [string]$BookmarkName, [string]$BookmarkURL) {
    function getBookmarkIDs($object){
        $object | ForEach-Object{
            "{0:0000}" -f [int]($_.id);
            if([bool]($_.PSobject.Properties.name -match "children")){
                GetBookmarkIDs($_.children);
            }
        }
    };
    $nextBookmarkID = [int](getBookmarkIDs -object $Bookmarks.roots.bookmark_bar|Sort-Object -Descending|Select-Object -First 1) + 1
    $currentChomeTime=[System.DateTimeOffset]::Now.ToUnixTimeMilliseconds()*10000;
    $newBookmark= [PSCustomObject]@{
        date_added=$currentChomeTime
        guid=[guid]::NewGuid()
        id=$nextBookMarkID
        name="$BookmarkName"
        type="url"
        url="$BookmarkURL"
    }
    return $newBookmark;
}
$newBookmark = createNewChromeBookmark -Bookmarks $dataBookmarks -BookmarkName "Google" -BookmarkURL "https://www.google.com/";
$dataBookmarks.roots.bookmark_bar.children += $newBookmark;
$dataBookmarksJSON = ConvertTo-Json -InputObject $dataBookmarks -Depth 100
Set-Content -Path $fileBookmarks -Value $dataBookmarksJSON -Encoding UTF8

```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [February 13, 2022, 8:14am UTC](https://forums.powershell.org/t/script-to-add-bookmarks-to-chrome/18567/2 "2022-02-13T08:14:15Z")

</div>

PatM,  
Welcome to the forum. 👋🏽

This forum is more about questions you have with code you wrote by yourself than reviewing, customizing or enhancing scripts you’ve found on the internet.

> [@PatM](#):
>
> I have found a script that does this

I’d recommend to ask the author of the script for help.

> [@PatM](#):
>
> I need to know how to add not just one bookmark but multiple.

The easiest solution would be to run the script multiple times. 😉

> [@PatM](#):
>
> I can see somewhat is going on with the script but I’m not familiar enough to understand enough to add more to the script to add multiple bookmarks.

It’s not that hard …

The first 2 lines read the bookmarks file.  
Line 3 to 23 define the needed functions  
Line 24 creates a new bookmark for the URL “[https://www.google.com/](https://www.google.com/)” with the name “Google”  
Line 25 adds this newly created bookmark to the already existing bookmarks in the variable `$dataBookmarks`  
Line 26 converts the PS objects containing all the bookmarks to a string representation in the format JSON.  
And the last line writes all this back to the disk.

Now it’s up to you to decide what lines you have to duplicate to add more than one bookmark. 😉

---

<div class="post-metadata">

**Author:** ![PatM](https://avatars.discourse-cdn.com/v4/letter/p/9d8465/32.png) [@PatM](https://forums.powershell.org/u/PatM)\
**Post date:** [February 13, 2022, 8:28pm UTC](https://forums.powershell.org/t/script-to-add-bookmarks-to-chrome/18567/3 "2022-02-13T20:28:58Z")

</div>

Thank you

I have an idea of what needs to be done as far as doing it again for another bookmark it’s just knowing the syntax needed to make it work.

I appreciate your input.

---

<div class="post-metadata">

**Author:** ![PatM](https://avatars.discourse-cdn.com/v4/letter/p/9d8465/32.png) [@PatM](https://forums.powershell.org/u/PatM)\
**Post date:** [February 13, 2022, 8:31pm UTC](https://forums.powershell.org/t/script-to-add-bookmarks-to-chrome/18567/4 "2022-02-13T20:31:19Z")

</div>

As far as the forum being for scripts I’ve written myself I understand. Is there another forum area here that would be more appropriate or do you have any suggestions for forums elsewhere that would?

Just looking for help and I appreciate your input.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [February 13, 2022, 10:24pm UTC](https://forums.powershell.org/t/script-to-add-bookmarks-to-chrome/18567/5 "2022-02-13T22:24:59Z")

</div>

> [@PatM](#):
>
> Is there another forum area here that would be more appropriate or do you have any suggestions for forums elsewhere that would?

As far as I’m concerned all free peer to peer forums focus on helping you helping yourself. And if you carefully read my first answer you have actually all you need. 😉 Have you concidered asking the author of the script for help?

---

<div class="post-metadata">

**Author:** ![PatM](https://avatars.discourse-cdn.com/v4/letter/p/9d8465/32.png) [@PatM](https://forums.powershell.org/u/PatM)\
**Post date:** [February 14, 2022, 1:16am UTC](https://forums.powershell.org/t/script-to-add-bookmarks-to-chrome/18567/6 "2022-02-14T01:16:32Z")

</div>

I understand and I do want to learn PowerShell. I kind of understand what’s happening in the script and I will be looking for what I need to do to add another bookmark. I was just wanting a little help but I will work on it because I want to fully understand how it works and be able to write scripts myself.

I will read over your reply again and work on it.  
Thank you

---

<div class="post-metadata">

**Author:** ![PatM](https://avatars.discourse-cdn.com/v4/letter/p/9d8465/32.png) [@PatM](https://forums.powershell.org/u/PatM)\
**Post date:** [February 15, 2022, 12:35am UTC](https://forums.powershell.org/t/script-to-add-bookmarks-to-chrome/18567/7 "2022-02-15T00:35:50Z")

</div>

I figured it out. It was way easier than I thought it would be. I was just overthinking it and expecting it to be harder.

As far as the person who wrote the script the last time he was on that forum was 2 years ago so I didn’t think he would respond.

Again, Thank you for the input!

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [February 15, 2022, 7:20am UTC](https://forums.powershell.org/t/script-to-add-bookmarks-to-chrome/18567/8 "2022-02-15T07:20:27Z")

</div>

> [@PatM](#):
>
> I figured it out.

Great. 👍🏽 I’m glad you’ve found a solution. 🙂

How about sharing your solution here? This could help others looking for the same or a similar problem in the future.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Alex\_PCW](https://avatars.discourse-cdn.com/v4/letter/a/8797f3/32.png) [@Alex\_PCW](https://forums.powershell.org/u/Alex_PCW)\
**Post date:** [January 24, 2024, 11:19pm UTC](https://forums.powershell.org/t/script-to-add-bookmarks-to-chrome/18567/9 "2024-01-24T23:19:12Z")

</div>

hi i was wondering if you where able to share your script that added multiple Bookmarks as i cannot find it online anywhere please

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [January 25, 2024, 4:23am UTC](https://forums.powershell.org/t/script-to-add-bookmarks-to-chrome/18567/10 "2024-01-25T04:23:31Z")

</div>

Closed on January 25, 2024, 4:23am UTC


