Need help improving my KQL query for Azure VM disk sizes

Joel Pangilinan 35 Reputation points
2023-02-14T19:16:15.9066667+00:00

Hi,

I have this KQL query wherein it list all VMs in my environment with OS and data disk sizes. However, whenever I include the 2 lines code which is highlighted in bold below, the output of the query excludes VMs with only OS disk. Basically the query shows only VMs with both OS and data disks. I want to have an output that includes VMs with OS disks. Can you please help improve on my query. Thanks.

| mv-expand DataDiskSizeInGB = properties.storageProfile.dataDisks

| extend DataDiskInGB = DataDiskSizeInGB.diskSizeGB

Resources
| where type in~ (
        "microsoft.compute/virtualmachines",
        "microsoft.scvmm/virtualmachines",
		"microsoft.connectedvmwarevsphere/virtualmachines",
		"microsoft.azurestackhci/virtualmachines")
| extend
    OSType = tostring(properties.storageProfile.osDisk.osType),
    OSDiskSizeInGB = tostring(properties.storageProfile.osDisk.diskSizeGB)
| mv-expand DataDiskSizeInGB = properties.storageProfile.dataDisks
| extend DataDiskInGB = DataDiskSizeInGB.diskSizeGB
| project id, name, location, resourceGroup, subscriptionId, OSType, OSDiskSizeInGB, DataDiskSizeInGB, properties
Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
Azure Disk Storage
Azure Disk Storage
A high-performance, durable block storage designed to be used with Azure Virtual Machines and Azure VMware Solution.
{count} vote

1 answer

Sort by: Most helpful
  1. shiva patpi 13,376 Reputation points Microsoft Employee Moderator
    2023-02-14T20:32:56.8466667+00:00

    Hello @Joel Pangilinan ,

    Can you try out the below query:

    Resources
    | where type in~ (
            "microsoft.compute/virtualmachines",
            "microsoft.scvmm/virtualmachines",
    		"microsoft.connectedvmwarevsphere/virtualmachines",
    		"microsoft.azurestackhci/virtualmachines")
            |  extend properties=parse_json(properties)
            | extend  name, DataDiskSizeInGB=properties.storageProfile.dataDisks[0].diskSizeGB , OSDiskSizeInGB=properties.storageProfile.osDisk.diskSizeGB,OSType = tostring(properties.storageProfile.osDisk.osType)
            | project id, name, location, resourceGroup, subscriptionId, OSType, OSDiskSizeInGB, DataDiskSizeInGB, properties
    
    

    Below is the output of above query in my local testing:

    User's image

    1 person found this answer helpful.
    0 comments No comments

Your answer

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