Microsoft Azure – 查找孤立磁盘
在本文中,您将了解如何在 Azure 中查找未附加的磁盘(也称为孤立磁盘)。删除孤立资源的主要目的或目的是节省未使用资源的成本。在 Azure 中删除 VM 时,磁盘不会自动删除,它们将作为孤立磁盘保留。
执行:
按照以下步骤在 Azure 中查找孤立磁盘:
步骤 1:登录到 Azure 门户。
步骤 2:转到 Azure Resource Graph Explorer >> 选择Resource Graph Explorer
第 3 步:选择范围 >> 订阅 >>选择您的订阅(您可以一次选择单个或多个订阅)
例如:在这里,我从 Scope 中选择了 8 个订阅。
第 4 步:将以下查询粘贴到查询框中,然后单击运行查询以获取未附加磁盘的列表/报告。
例子:
Resources
| where type has "microsoft.compute/disks"
| extend diskState = tostring(properties.diskState)
| where diskState == 'Unattached' or managedBy == ""
| project name, diskState, managedBy, subscriptionId, resourceGroup, location
输出:
示例 1:如果您在范围内选择了多个订阅,那么您将获得许多结果 >> 在这种情况下,您可以添加订阅 ID 具有“_SubscriptionId_Value”的位置以获取特定选择订阅中的结果。
Resources
| where type has "microsoft.compute/disks"
| extend diskState = tostring(properties.diskState)
| where diskState == 'Unattached' or managedBy == ""
| where subscriptionId has ""
| project name, diskState, managedBy, subscriptionId, resourceGroup, location
输出:
示例 2:如果您希望将标记值的结果发送到该孤立磁盘,则可以使用以下kql命令。
Resources
| where type has "microsoft.compute/disks"
| extend diskState = tostring(properties.diskState)
| where diskState == 'Unattached' or managedBy == ""
| where subscriptionId == ""
| where tags.Environment == "Production" // "Dev", "Prod", "Test",...etc.
| project name, diskState, managedBy, subscriptionId, resourceGroup, location, tags
输出:
就是这样,你就完成了。