roy*_*roy 5 powershell json powershell-4.0
我试图使用PowerShell从JSON对象中提取值,我有以下JSON:
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"clusterName": {
"value": "hbasehd35"
},
"location": {
"value": "East US 2"
},
"clusterType": {
"value": "hbase"
},
"clusterVersion": {
"value": "3.5"
},
"clusterWorkerNodeCount": {
"value": 5
},
"subnetName": {
"value": "hbase-subnet"
},
"headNodeSize": {
"value": "Standard_D12_v2"
},
"workerNodeSize": {
"value": "Standard_D12_v2"
},
"zookeeperSize": {
"value": "Large"
},
"clusterStorageAccountName": {
"value": "hbasestorage"
},
"storageAccountType": {
"value": "Standard_GRS"
},
"Environment": {
"value": "test"
}
}
}
Run Code Online (Sandbox Code Playgroud)
在这里,我想clusterStorageAccountName使用powershell从此文件中提取,并将其分配给变量.
有人知道怎么做吗 ?
使用Get-Contentcmdlet读取文件,使用ConvertFrom-Jsoncmdlet 转换它,然后只需访问所需的属性:
$yourVariable = (Get-Content 'yourJsonFilePath.json' | ConvertFrom-Json).parameters.clusterStorageAccountName.value
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6609 次 |
| 最近记录: |