Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用PowerShell更新json文件中属性的值?_Json_Powershell_Powershell 4.0_Powershell 5.0 - Fatal编程技术网

如何使用PowerShell更新json文件中属性的值?

如何使用PowerShell更新json文件中属性的值?,json,powershell,powershell-4.0,powershell-5.0,Json,Powershell,Powershell 4.0,Powershell 5.0,我在PowerShell脚本中遇到了一个问题,需要将名为restServiceURL和microServiceURL的属性的部分值从http更新为https。(以下截图) 我有下面的脚本,但不知何故,我无法确定需要添加哪些内容才能将属性值的特定部分(本例中为http)从“http://vwmamipkg16sn/IMatchREST/”替换为“https://vwmamipkg16sn/IMatchREST/” 我知道set content命令应该能够做到这一点,但如何在不改变值的其他部分的情

我在PowerShell脚本中遇到了一个问题,需要将名为restServiceURL和microServiceURL的属性的部分值从http更新为https。(以下截图)

我有下面的脚本,但不知何故,我无法确定需要添加哪些内容才能将属性值的特定部分(本例中为http)从“http://vwmamipkg16sn/IMatchREST/”替换为“https://vwmamipkg16sn/IMatchREST/”

我知道set content命令应该能够做到这一点,但如何在不改变值的其他部分的情况下做到这一点,是我一直无法解决的问题

任何关于这方面的建议都会有所帮助

# Code to get Installation Directory path
$CommonNode=Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\AquagardePI\STeP\Platform\Common
$InstallationDir=$CommonNode.InstallationDir

#Path of Json File
$ConfigPath = $InstallationDir + "Web Client\www\\NextGen\assets\config.json"

#Get Content of the File
$file = Get-Content $ConfigPath -raw | ConvertFrom-Json

#Get the value of Property
$file = $file.restServiceURL

您可以首先获取JSON对象,然后简单地将您感兴趣的两个属性的
http
替换为
https

$ConfigPath = $InstallationDir + "Web Client\www\\NextGen\assets\config.json"
$file = Get-Content $ConfigPath -raw | ConvertFrom-Json

$file.microServiceURL = $file.microServiceURL.Replace('http','https')
$file.restServiceURL = $file.restServiceURL.Replace('http','https')

Set-Content -Value ($file | ConvertTo-Json) -Path $ConfigPath