简体   繁体   中英

How to dynamically get all nested properties from JSON Array object (example VM data disks) in Azure resource graph

I am trying to get all data disks attached to a Azure VM from Azure Resource Graph Query. I am able to get specific data disk by specifying the index( for example properties.storageProfile.dataDisks[0].name for first disk) but but how do I get this dynamically when more than 1 data disks are attached.

  1. Row per disk
resources
| where ['type'] == 'microsoft.compute/virtualmachines' 
| mv-expand with_itemindex = i properties.storageProfile.dataDisks
| extend DataDiskName       = properties_storageProfile_dataDisks.name 
        ,DataDiskSizeGB     = properties_storageProfile_dataDisks.diskSizeGB 
        ,DataDiskSizeType   = properties_storageProfile_dataDisks.managedDisk.storageAccountType 
  1. Column per disk
resources
| where ['type'] == 'microsoft.compute/virtualmachines' 
| mv-expand with_itemindex=i dataDisk = properties.storageProfile.dataDisks
| extend dataDisk = pack_array(dataDisk.name, dataDisk.diskSizeGB, dataDisk.managedDisk.storageAccountType)
| summarize dataDisk0 = anyif(dataDisk, i == 0)
           ,dataDisk1 = anyif(dataDisk, i == 1)
           ,dataDisk2 = anyif(dataDisk, i == 2)
           ,dataDisk3 = anyif(dataDisk, i == 3)
           ,dataDisk4 = anyif(dataDisk, i == 4)
           by id 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM