VMware Cloud Community
akyster
Contributor
Contributor
Jump to solution

Evaluating disk space consumption

I would like to be able to extract a list of VM's that shows me the actual size of the vmdk file(s), seen from the hypervisor and from the guest. This way I would be able to determine which VM's are candidates for an Sdelete-and-SVM operation.

All scripts i have come across so far only gives me the provisioned size of a vmdk file.

Any advice?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The following will give you a 'raw' dump of all the files that make up your vDisks per VM

foreach($vm in Get-VM){
    $diskFiles = $vm.ExtensionData.LayoutEx.Disk | %{$_.Chain} | %{$_.FileKey}
    $vm.ExtensionData.LayoutEx.File | where{$diskFiles -contains $_.Key } | 
    Select @{N="VM";E={$vm.Name}},Name,Size
}

With grouping you can make size subtotals per VMDK and per VM


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

View solution in original post

0 Kudos
7 Replies
LucD
Leadership
Leadership
Jump to solution

The diskspace consumption from within the guest is not obvious.

Multiple methods have been tried, but none is 100% satisfactory.

Some of the problem:

  • a VMDK file can contains multiple guest OS partitions
  • the link between the VMDK file and the OS partitions is available directly

Some scripts have used the SCSI-Id to map the VMDK file to the partitions inside the guest OS, others have used WMI calls to retrieve the partitions.

One method that seems to work most of the time, Linux systems excluded, is the script from Arnim.

See his PowerCLI: Match VM and Windows harddisks – Part 2 post.


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

0 Kudos
akyster
Contributor
Contributor
Jump to solution

If I could just get a list (per VM) of the VMDK files associated with the VM, their actual size, and a list of disks as seen from the guest, that would work for me 95% of the time. The rest I can check by hand.

Getting the actual size of the VMDK is the main issue. Is this possible?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The following will give you a 'raw' dump of all the files that make up your vDisks per VM

foreach($vm in Get-VM){
    $diskFiles = $vm.ExtensionData.LayoutEx.Disk | %{$_.Chain} | %{$_.FileKey}
    $vm.ExtensionData.LayoutEx.File | where{$diskFiles -contains $_.Key } | 
    Select @{N="VM";E={$vm.Name}},Name,Size
}

With grouping you can make size subtotals per VMDK and per VM


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

0 Kudos
akyster
Contributor
Contributor
Jump to solution

Exactly what the doctor ordered. Thanks.

How do I limit the list to disks of type diskExtent only?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

With an extra condition in the Where-clause

foreach($vm in Get-VM){
    $diskFiles = $vm.ExtensionData.LayoutEx.Disk | %{$_.Chain} | %{$_.FileKey}
    $vm.ExtensionData.LayoutEx.File | where{$diskFiles -contains $_.Key -and $_.Type -eq "diskExtent"} | 
    Select @{N="VM";E={$vm.Name}},Name,Size
}

Note that I changed the previous code as well, you have to use the Key with the index numbers, not the array index.

Most of the time it will work, but there are exceptions where the Key doesn't correspond with the array index.


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

0 Kudos
akyster
Contributor
Contributor
Jump to solution

This is my preliminary rough code that outputs what I want for a single named VM. Feel free to expand.

Difference between thin VMDK-file size and OS-reported disk usage can be reclaimed by doing a SDelete (warning: this expands the VMDK to almost full size, make sure you have enough space on your datastore) and then SVM the disk to a datastore with a different blocksize. This will reclaim the free space in the VMDK.

The call to GWMI requires proper credentials and tcp 135 plus a random high tcp port.

Enjoy!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Interesting script, thanks for sharing.


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

0 Kudos