1

我正在尝试从 Azure Resource Graph Query 获取 VM 上存在的所有数据磁盘。我可以通过指定索引来获取特定的数据磁盘(例如第一个磁盘的 properties.storageProfile.dataDisks[0].name),但是我如何动态地获取它,因为有些数据磁盘超过 1 个。如果 VM 有 3 个磁盘,是否可以获取详细信息并将其放入值为“disk1、disk2、disk3 等”的新列中。使用下面我可以提取第一个磁盘。

  resources
| where ['type'] == 'microsoft.compute/virtualmachines'
| extend DataDiskName = properties.storageProfile.dataDisks[0].name
| extend DataDiskSizeGB = properties.storageProfile.dataDisks[0].diskSizeGB
| extend DataDiskSizeType = properties.storageProfile.dataDisks[0].managedDisk.storageAccountType
4

1 回答 1

0
let resources = datatable(id:int,type:string,properties:dynamic)
[
    1 ,'microsoft.compute/virtualmachines', dynamic({"storageProfile":{"dataDisks":[{"name":"dd11","diskSizeGB":11,"managedDisk":{"storageAccountType":"sat11"}}]}})
   ,2 ,'microsoft.compute/virtualmachines', dynamic({"storageProfile":{"dataDisks":[{"name":"dd21","diskSizeGB":21,"managedDisk":{"storageAccountType":"sat21"}},{"name":"dd22","diskSizeGB":22,"managedDisk":{"storageAccountType":"sat22"}},{"name":"dd23","diskSizeGB":23,"managedDisk":{"storageAccountType":"sat23"}}]}})
   ,3 ,'microsoft.compute/virtualmachines', dynamic({"storageProfile":{"dataDisks":[{"name":"dd31","diskSizeGB":31,"managedDisk":{"storageAccountType":"sat31"}},{"name":"dd32","diskSizeGB":32,"managedDisk":{"storageAccountType":"sat32"}}]}})
];
resources
| where ['type'] == 'microsoft.compute/virtualmachines'
| mv-apply with_itemindex=i dd = properties.storageProfile.dataDisks on (summarize properties = make_bag(pack(strcat(i+1,"_name"),dd.name, strcat(i+1,"_diskSizeGB"),dd.diskSizeGB, strcat(i+1,"_storageAccountType"),dd.managedDisk.storageAccountType)))
| evaluate bag_unpack(properties)

在此处输入图像描述

小提琴

于 2022-02-25T15:39:30.227 回答