PowerCli: Finding amount of GB used by VMs in a folder/vApp/datacenter

Sometimes it can be useful to know how much space the VMs in a specific folder (or vApp/datacenter) is occupying. For example if you are a hosting provider of some sort and need to know how much space a customer is using.

It’s a simple one-liner!

Get-VM -Location <name of folder/vApp/datacenter> | foreach {Get-HardDisk -VM $_.name} | Measure-Object CapacityGB -Sum

That will give an output that looks something like this:
temp
Meaning, in this case, that the folder named “Templates” has 2 VMs occupying 140GB of disk space

You can also get a list per vm with this one-liner:

get-vm -Location <folder> | select name,@{Name="Size";Expression={(Get-HardDisk -VM $_.name |
Measure-Object CapacityGB -sum).Sum}}
Category(s): PowerCLI, Powershell, VMware
Tags: , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.