我正在Powershell中寻找一种方法来删除和添加书签到chrome。 Chrome书签以以下格式存储在JSON文件中,而实际的书签则存储在$ data.roots.bookmark_bar.children对象中。我已经尝试过这样的事情:
$data = Get-content $chromebookmarkfile | out-string | ConvertFrom-Json
$data | Where-Object {$data.Roots.Bookmark_bar.children.Name -Notmatch "^NA"} | Convertto-JSON | Out-File "C:\Users\Name\Desktop\bookmarkupdated.js"
似乎删除了所有书签。
> { "checksum": "f8d56bf82388c64d566247e1f510d0c8", "roots": {
> "bookmark_bar": {
> "children": [ {
> "date_added": "13186673111751399",
> "id": "5",
> "meta_info": {
> "last_visited_desktop": "13189831127309905"
> },
> "name": "Facebook",
> "type": "url",
> "url": "https://www.facebook.com/"
> }],
> "date_added": "13186673028532299",
> "date_modified": "13189832329106862",
> "id": "1",
> "name": "Bookmarks bar",
> "type": "folder"
> },
> "other": {
> "children": [ ],
> "date_added": "13186673028532314",
> "date_modified": "0",
> "id": "2",
> "name": "Other bookmarks",
> "type": "folder"
> },
> "synced": {
> "children": [ ],
> "date_added": "13186673028532317",
> "date_modified": "0",
> "id": "3",
> "name": "Mobile bookmarks",
> "type": "folder"
> } }, "version": 1 }
感谢您的帮助。
答案 0 :(得分:2)
您可以这样做:
$json = Get-Content $chromebookmarkfile -Raw | ConvertFrom-Json
$json.Roots.Bookmark_bar.children = @($json.Roots.Bookmark_bar.children | where { $_.name -notmatch "^NA" })
$json | ConvertTo-Json -Depth 10 | Out-File "C:\Users\Name\Desktop\bookmarkupdated.js" -Encoding UTF8