VMware Cloud Community
timgerr
Contributor
Contributor

Question about getting Size of Virtual Machine

Hello all, I have a problem that I am working

on. I need to get the size of a virtual machine that was created and space on the datastore. Is that possible via Power

Shell?

Reply
0 Kudos
3 Replies
LucD
Leadership
Leadership

I suspect something went wrong with your submission.

What "size" did you have in mind ? Size on disk, memory size...


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
timgerr
Contributor
Contributor

Size on disk.

Tim

Reply
0 Kudos
Zsoldier
Expert
Expert

The easy way is to use the GUI. To get hard disk sizes for your VM's:

(Get-VM VMName).Harddisks

This will list all disks associated with the VM. Add these numbers together with the amount of RAM you have allocated to the VM and you get how much space the VM is taking up on a datastore. Below shows how you can add it all together.

((Get-VM VMName).Harddisks | foreach {$_.CapacityKB / 1kb} | measure-object -sum).sum + (get-vm vmname).MemoryMB

More efficiently and faster would look like below:

$VMName = Get-VM VMName

($VMName.Harddisks | foreach {$_.CapacityKB / 1kb} | measure-object -sum).sum + $VMName.MemoryMB

K. Chris Nakagaki (Zsoldier)

http://tech.zsoldier.com

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier
Reply
0 Kudos