我试图使用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" } } }
在这里,我想clusterStorageAccountName
使用powershell从此文件中提取,并将其分配给变量.
有人知道怎么做吗 ?
使用Get-Content
cmdlet读取文件,使用ConvertFrom-Json
cmdlet 转换它,然后只需访问所需的属性:
$yourVariable = (Get-Content 'yourJsonFilePath.json' | ConvertFrom-Json).parameters.clusterStorageAccountName.value