2

I want to ask a question about thin provisioning. get-vm commandlet can easly give us real space used by a vm totally. Assume that you have a virtual machine which has more than one thin disk. If we want to get more detail so as to calculate each disk real used space which powercli command does this? I do not prefer getting it by datastore browser for performance issues.

2 Answers 2

2

The actual used disk space is retrievable without accessing the datastore separately, but you won't find the information in the disk object, but rather in the VM object. It is hidden in $vm.ExtensionData.LayoutEx.File, which contains information about all files related to the VM, not only the disk files. So the trick is to get the file information that relates to the queried disk.

If you only want the actual size, and nothing else, you can do it really quick like this:

(get-vm vmname).ExtensionData.LayoutEx.File |
    Where-Object { $_.name -like '*-flat.vmdk' } |select Name,Size

Name                                                        Size
----                                                        ----
[Datastore1] vmname/vmname-flat.vmdk                 53895368934
[Datastore1] vmname/vmname_1-flat.vmdk               73348843320
[Datastore1] vmname/vmname_2-flat.vmdk              268902888606
[Datastore1] vmname/vmname_3-flat.vmdk               37724234832

If you want some more information about the disks:

get-vm $vmname |Get-HardDisk |
    Select name,capacitygb,StorageFormat,@{name="UsedSpaceGB";e={ 
        $disk=$_;
        [math]::Round(($disk.Parent.ExtensionData.LayoutEx.File |
            Where-Object {
                $_.name -eq $disk.Filename.Replace(".","-flat.")
            }).Size/1GB,2) 
    }}

Name        CapacityGB    StorageFormat UsedSpaceGB
----        ----------    ------------- -----------
Hard disk 1         50 EagerZeroedThick       50,19
Hard disk 2        100             Thin       68,31
Hard disk 3        300             Thin      250,44
Hard disk 4         60             Thin       35,13
0

I found the following solution:

(Get-VM -Name $YourVmName).Extensiondata.Guest.Disk

This command will give you all the disks of this vm with the provisioned size and the free space - with that you can calculate the real used size.

Source (with a complete script to list all disks): http://www.vstrong.info/2014/03/28/vmware-powercli-script-to-list-thin-provisioned-virtual-disks-vmdk/

1
  • 1
    That is in no way a answer to OP's question. It reports usage within the guest, not the space used by a VMDK. If you delete a bunch of files from the guest it will free the space inside the guest, but will not shrink the VMDK. All you did was google OP's question and post the first result without understanding the question, or powershell commands.
    – Muh Fugen
    Oct 4, 2017 at 6:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .