How can I get disk data (total size and used size in GB) for multiple Win VMs ?

$@chin 115 Reputation points
2024-08-11T14:43:54.4766667+00:00

How can I fetch or extract disk data that includes the total disk size and used disk size based on drive instances (e.g., C: , E: & other drives) across multiple Windows VMs? I don’t need the data in percentage.

I tried the following query, but the results were not as expected and seemed incorrect.

Perf

| where ObjectName == "LogicalDisk" and CounterName == "Free Megabytes"

| summarize TotalDiskSpace_GB = (max(CounterValue) + sum(CounterValue)/1024), UsedDiskSpace_GB = (sum(CounterValue)/1024),Freespace_GB = ((max(CounterValue) + sum(CounterValue))-sum(CounterValue)/1024) by Computer, InstanceName

User's image

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
3,273 questions
Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
5,404 questions
Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,907 questions
Azure Disk Storage
Azure Disk Storage
A high-performance, durable block storage designed to be used with Azure Virtual Machines and Azure VMware Solution.
633 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,526 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Marcin Policht 24,440 Reputation points MVP
    2024-08-11T15:00:06.9633333+00:00

    Try the following

    Perf
    | where ObjectName == "LogicalDisk" and (CounterName == "Free Megabytes" or CounterName == "Disk Size (MB)")
    | summarize 
        TotalDiskSpace_GB = maxif(CounterValue, CounterName == "Disk Size (MB)") / 1024, 
        Freespace_GB = maxif(CounterValue, CounterName == "Free Megabytes") / 1024, 
        UsedDiskSpace_GB = (maxif(CounterValue, CounterName == "Disk Size (MB)") - maxif(CounterValue, CounterName == "Free Megabytes")) / 1024 
      by Computer, InstanceName
    | order by Computer, InstanceName asc
    
    

    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin


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.