我试图使用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"
}
}
}
在这里,我想从使用PowerShell这个文件中提取clusterStorageAccountName
,并将其分配给变量。
有人知道怎么做吗 ?
使用Get-Content
cmdlet来读取文件,使用ConvertFrom-Json
cmdlet的转换它,只是访问所需的属性:
$yourVariable = (Get-Content 'yourJsonFilePath.json' | ConvertFrom-Json).parameters.clusterStorageAccountName.value
我不知道为什么,但是从消息的方法上面没有为我工作。但工程刚开始键,你需要通过后“ConvertFrom JSON的”命令,e.g关键:
$yourVariable = (Get-Content 'yourJsonFilePath.json' | ConvertFrom-Json).clusterStorageAccountName