VMware Cloud Community
wamatha
Contributor
Contributor

Total disk usage per vm

I need help!

I am looking for a script tht can generate a report on total disk used per VM, in GB

0 Kudos
3 Replies
mcowger
Immortal
Immortal

Something like this would be a good start:

Get-VM | Get-HardDisk | Format-Table -GroupBy Parent

Gives you the virtual hard disks per VM along with filename and capacity in KB.  You could use a calculated property to convert that to GB if needed.

--Matt VCDX #52 blog.cowger.us
0 Kudos
mattboren
Expert
Expert

Hello, wamatha-

mcowger definitely points you in the right direction with his post.  Another way, using Get-VM, is like:

Get-VM | Select Name,UsedSpaceGB

Or, if you want some speed on that script (like I do), you could use:

Get-View -ViewType VirtualMachine -Property Name,Summary.Storage.Committed |
   
Select Name,
        @{n
="UsedSpaceGB"; e={[Math]::Round(($_.Summary.Storage.Committed / 1GB), 2)}}

This should be far faster than the Get-VM route, especially as the VM count rises.  Note:  the second way includes templates, which could easily be filtered out if desired.

0 Kudos
wamatha
Contributor
Contributor

works well, but for clustered vm's with RDM's it's total is wrong, instead of only showing say one vm with RDM totals, all other vm's in the cluster have their sum totals including the rdms as well

0 Kudos