0
votes

I have been trying to create a script that can get a list of all managed disks in Azure, which includie vmname, diskname, size, OSType and resource group name and more importantly free space and available disk space remaining.

I can get the basic information using Powershell, however I can't seem to get current disk usage and free space remaining, I was hoping some guidance or point in the right direction.

$vms = Get-AzureRmVM 
foreach ($vm in $vms) {
Get-AzureRmDisk | select -Property $vm.Name,Name,DiskSizeGB,OSType,ResourceGroupName
}

Thanks in advance

2

2 Answers

2
votes

Based on my knowledge, it is not possible. You could check managed disk rest APi. Azure does not provide such parameters.

So, you could not use Azure Power Shell to get managed disk usage information, you only could get total space.

One solution, you need login your VM and use command to get your disk usage.

1
votes

You also could use a Hybrid-Worker and run this Command:

Getting all local Disks (exclude the Temp-Drive D)

$Disks = get-WmiObject win32_logicaldisk `
| Where-Object -Property VolumeName -ne "Temporary Storage"

Calculate the free Space in Percent and create a PS Custom Object

$Report = @()
foreach ($Disk in $Disks) {
    $myObject = [PSCustomObject]@{
        Hostname     = hostname
        Disk         = $Disk.DeviceID
        FreeSpace    = [math]::Round((($Disk.FreeSpace * 100) / $Disk.Size),0)
    }
    $Report += $myObject
}

and store the Result in a StorageAccount Table