我正在编写一个Powershell脚本,该脚本使用Chrome的JSON书签文件删除和更新特定的书签。我可以很好地添加单个书签,问题是将文件夹添加到书签栏并进一步嵌套JSON。
我尝试了以下代码,并将每个书签作为单独的书签添加,而不是嵌套在文件夹中。同样,在JSON输出中,有几行仅表示NULL。
$addchild = @"
"@
$addparent = @"
"@
foreach($folderitem in $foldernames)
{
foreach($item in $bookmarkfile | where {$_.Type -eq "bookmark" -and $_.folder -eq "$($folderitem)" } )
{
$addchild +@"
{
"date_added": "13189713135962484",
"id": "$($bmid)",
"meta_info": {
"last_visited_desktop": "00000000000000000"
},
"name": "$($item.Name)",
"type": "url",
"url": "$($item.Link)"
}
"@
$bmID -= 1
}
$addparent +@"
{
"children": "$addchild",
"date_added": "13149631693871500",
"date_modified": "13160172856345996",
"id": "$($folderID)",
"name": "$($folderitem)",
"type": "folder"
}
"@
$folderID -= 1
$json.roots.bookmark_bar.children += (ConvertFrom-Json -InputObject
$addparent)
$addparent = @"
"@
$addchild = @"
"@
}
$json | ConvertTo-Json -Depth 7 | Out-File "$($ChromePath)\bookmarks" -Encoding UTF8