我面临的问题是使用 powershell 修改 json 文件中的值
I am facing issue is modifying a value in json file using powershell
我有一个包含以下内容的 json 文件
{
"createOrReplace": {
"object": {
"database": "DB_NAME"
},
"database": {
"name": "DB_NAME",
"compatibilityLevel": 1400,
"model": {
"culture": "en-IN",
"dataSources": [{
"name": "somename",
"connectionString": "somevalue",
"impersonationMode": "impersonateServiceAccount",
"annotations": [{
"name": "ConnectionEditUISource",
"value": "SqlServer"
}]
}]
}
}
}
}
并且我正在使用以下 PowerShell 脚本来更新 dataSources
下的 name
。
$JsonFilePath = "path-to-json-file"
$JsonData = Get-Content $JsonFilePath -raw | ConvertFrom-Json
$JsonData.createOrReplace.database.model.dataSources[0].name = "ssasservername"
$JsonData | ConvertTo-Json | set-content $JsonFilePath
谁能帮我在数组中设置一个对象的值?
$JsonData.createOrReplace.database.model.dataSources[0].name = "ssasservername"
另请注意::
$JsonData | ConvertTo-Json -Depth 9 | set-content $JsonFilePath
我有一个包含以下内容的 json 文件
{
"createOrReplace": {
"object": {
"database": "DB_NAME"
},
"database": {
"name": "DB_NAME",
"compatibilityLevel": 1400,
"model": {
"culture": "en-IN",
"dataSources": [{
"name": "somename",
"connectionString": "somevalue",
"impersonationMode": "impersonateServiceAccount",
"annotations": [{
"name": "ConnectionEditUISource",
"value": "SqlServer"
}]
}]
}
}
}
}
并且我正在使用以下 PowerShell 脚本来更新 dataSources
下的 name
。
$JsonFilePath = "path-to-json-file"
$JsonData = Get-Content $JsonFilePath -raw | ConvertFrom-Json
$JsonData.createOrReplace.database.model.dataSources[0].name = "ssasservername"
$JsonData | ConvertTo-Json | set-content $JsonFilePath
谁能帮我在数组中设置一个对象的值?
$JsonData.createOrReplace.database.model.dataSources[0].name = "ssasservername"
另请注意:
$JsonData | ConvertTo-Json -Depth 9 | set-content $JsonFilePath