简体   繁体   English

如何从 Azure 资源图中的 JSON 数组 object(示例 VM 数据磁盘)动态获取所有嵌套属性

[英]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.我正在尝试从 Azure 资源图查询获取连接到 Azure VM 的所有数据磁盘。 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.我可以通过指定索引(例如 properties.storageProfile.dataDisks[0].name 用于第一个磁盘)来获取特定的数据磁盘,但是当连接了多个数据磁盘时我如何动态地获取它。

  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 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何以编程方式加密 Azure VM 数据磁盘 - How to programatically encrypt azure VM data disks 如何使用 azure 资源图获取 Azure VM 最后一次重启 - how to get Azure VM last reboot using azure resource graph Azure VM合并数据磁盘 - Azure VM Merge Data Disks Azure 虚拟机备份 - 从仅 OS 磁盘更改为所有磁盘 - Azure Vm Backup - change from OS Disk only to all disks 如何从 ARM 模板部署初始化/格式化 Azure Windows VM 的数据磁盘? - How to initialize/format Azure Windows VM's Data Disks from ARM Template Deployment? Terraform Azure:如何在从自定义映像配置 VM 时配置数据磁盘类型 - Terraform Azure: how to configure Type of Data Disks when VM is provisioned from a Custom Image Azure-cli 删除所有 VM 和磁盘以及资源组下的所有内容 - Azure-cli Remove all VM and disks and everything under resource group Azure使用Azure资源图计算VMSS中的所有VM - Azure count all VM's in VMSS using Azure Resource Graph 在 Azure 中重新部署 VM 资源的 ARM 模板期间,操作系统托管磁盘上的数据是否保留? - Is the data on OS managed disks preserved during ARM template redeployment of a VM resource in Azure? 在Azure中将数据磁盘附加到VM时出现节流/错误? - Throttling/errors when attaching data disks to VM in Azure?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM