Automation

 View Only
  • 1.  Evaluating disk space consumption

    Posted Nov 24, 2011 07:59 AM

    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?



  • 2.  RE: Evaluating disk space consumption

    Posted Nov 24, 2011 08:21 AM

    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.



  • 3.  RE: Evaluating disk space consumption

    Posted Nov 24, 2011 08:52 AM

    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?



  • 4.  RE: Evaluating disk space consumption
    Best Answer

    Posted Nov 24, 2011 09:24 AM

    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



  • 5.  RE: Evaluating disk space consumption

    Posted Nov 24, 2011 09:59 AM

    Exactly what the doctor ordered. Thanks.

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



  • 6.  RE: Evaluating disk space consumption

    Posted Nov 24, 2011 10:17 AM

    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.



  • 7.  RE: Evaluating disk space consumption

    Posted Nov 24, 2011 01:59 PM

    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!



  • 8.  RE: Evaluating disk space consumption

    Posted Nov 24, 2011 05:13 PM

    Interesting script, thanks for sharing.