使用powershell替换JSON中的布尔值

使用powershell替换JSON中的布尔值,json,powershell,Json,Powershell,我试图使用powershell更新JSON格式文件中的布尔值,但没有得到所需的输出 从下面 { "setComputerName": false, "setWallpaper": true } 我想得到的输出是 { "setComputerName": true, "setWallpaper": true } 下面是我的剧本 $file = Get-Content 'C:\temp\Config.json' -raw | ConvertFrom-Json $file = $file.

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

从下面

{
"setComputerName":  false,
"setWallpaper":  true
}
我想得到的输出是

{
"setComputerName":  true,
"setWallpaper":  true
}
下面是我的剧本

$file = Get-Content 'C:\temp\Config.json' -raw | ConvertFrom-Json
$file = $file.setComputerName = 'true'
$file | ConvertTo-Json  | set-content 'C:\temp\Config1.json'

导入json后需要做的就是

$file.setComputerName=$true
$file | ConvertTo-Json  | set-content 'C:\temp\Config1.json'
您试图将该值设置为字符串,它需要是布尔值,因此需要使用$true或$false来设置这些值


希望这有帮助

导入json后需要做的就是

$file.setComputerName=$true
$file | ConvertTo-Json  | set-content 'C:\temp\Config1.json'
您试图将该值设置为字符串,它需要是布尔值,因此需要使用$true或$false来设置这些值


希望这有帮助

嗨。为了便于将来参考,最好将不正确的输出(或异常详细信息)与所需的输出一起发布,以便人们更好地了解问题。@DeanOC I agreeHi。作为将来的参考,最好将不正确的输出(或异常详细信息)与所需的输出一起发布,以便人们更好地了解问题。@DeanOC我同意就是这样。工作很认真。谢谢你的提醒。@CDP CDP没问题!就是这样。工作很认真。谢谢你的提醒。@CDP CDP没问题!