azureazure-managed-disk

How can I get the used/free managed disk size on Azure VMs?


I have some Azure VMs, and appended some managed disks to the. But is it possible that get the free/used size of these managed disks?

I have tried Get-AzDisk powershell command.However it only returns the total size if Disks instead of the used/free size of a disk. How can I get used/free size of a disk by PowerShell?


Solution

  • You can use the Run command functionality to do this. For windows VMs please refer to this link and this link is for Linux VMs.

    For instance, if you are using Azure Windows VM, you can use PowerShell Command below to get the information you need:

    $vm = Get-AzVM -Name <vm name> -ResourceGroupName <Resource Group Name>
    
    $result = Invoke-AzVMRunCommand -VM $vm -CommandId 'RunPowerShellScript' -ScriptPath '<path of your PS script that run inside of VM>'
    
    $result.Value[0].Code
    $result.Value[0].Message
    

    Content of PS script that runs inside of VM:

    Get-WmiObject Win32_LogicalDisk | Select-Object DeviceID,size,FreeSpace
    

    Result: enter image description here