使用powershell替换JSON中的布尔值



我试图使用powershell更新JSON格式文件中的布尔值,但没有得到所需的输出。

从下面来看,

{
"setComputerName":  false,
"setWallpaper":  true
}

我想得到的输出

{
"setComputerName":  true,
"setWallpaper":  true
}

下面是我的脚本,

$file = Get-Content 'C:tempConfig.json' -raw | ConvertFrom-Json
$file = $file.setComputerName = 'true'
$file | ConvertTo-Json  | set-content 'C:tempConfig1.json'

导入json后所要做的就是.

$file.setComputerName=$true
$file | ConvertTo-Json  | set-content 'C:tempConfig1.json'

您试图将该值设置为字符串,并且它需要是布尔值,因此需要使用$true或$false来设置这些值。

希望这能有所帮助!

最新更新