How to get a list of replicated disks associated with virtual machines in Azure using Azure Resource Graph query?

Monitor 2512 5 Reputation points
2024-10-01T16:24:26.3966667+00:00

How can I use Azure Resource Graph to query for virtual machines and their associated replicated disks in Azure? I would also like to include the tag information for both the virtual machines and their replicated disks.

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,982 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Srinud 2,610 Reputation points Microsoft Vendor
    2024-10-23T01:46:03.6566667+00:00

    Hi Monitor,

    Could you please try the query below. Make sure to adjust the query according to your data.

    Resources
    | where type =~ 'microsoft.compute/virtualMachines' or type =~ 'microsoft.compute/disks'
    | project id, name, type, resourceGroup, location, tags, properties
    | join (
        Resources
        | where type =~ 'microsoft.compute/disks' and properties.replicationStatus =~ 'Replicating'
        | project diskId, vmId, diskName, diskTags, properties
    ) on id
    | project vmId, vmName = name, vmTags = tags, vmLocation = location, vmResourceGroup = resourceGroup, vmType = type, vmProperties = properties, diskId, diskName, diskTags, diskLocation = location, diskResourceGroup = resourceGroup, diskType = type, diskProperties = properties
    

    If the information is helpful, please consider by clicking the "Accept answer and Upvote" on the post. If you are still facing any issue, please let us know in the comments.

    Thank you.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.