VM Disks and Total Size

How many disks (vmdks) and what is the total configured size of these Virtual Machines (VMs)? Currently moving a large number of VMs across datastores using vSphere’s Storage VMotion, now I need to figure out how big each VM is, or rather configured to be, since a number of the VMs are currently thin provisioned. Since there a number that are thin provisioned I need to know how big the disks have been configured to be to allow sufficient space in the destination datastores.
Originally thin provisioned by the users due to lack of space, however new additional datastores have been created and now we do not need to this type of provisioning. That and the cluster is having performance issues related to the SATA disk arrays they are on. (Not enough FC disk in our SAN array) Exchange, SCCM, SCOM etc are not servers that really benefit from having thin provisioned disks, this from best practice guides and now personal experience. Given the space constraints we had at the time there was no real alternative available to us. You do what you can with what you have, as they say.
So i wrote this little function create a list of the VMs I wish to move from the source datastores to help me work out what the target datastores they should go on.

function Get-VMDiskInfo 
{
  param(
        [Parameter(
            Mandatory=$true,
            ValueFromPipeline=$true,
            HelpMessage="VM"
        )]
        [VMware.VimAutomation.Types.VirtualMachine]
        $VM
  )

  Process {
    #display VM name, number of VMDKs and add up all the vmdk sizes to display a total in GB
    #Get-Datastore -Name MySourceDatastore | Get-VM | Get-VMDiskInfo
    #Name    Disks   TotalSizeGB
    #myvm1     2        96
    Write-Debug "$vm.Name `t -NoNewLine"
    $hddcount = 0
    $TotalSize = 0
    foreach ($hdd in $vm.harddisks) 
    {
      $hddcount ++
      $TotalSize += $hdd.CapacityKB/1MB
    } #end foreach 
    Write-Debug "$hddcount `t $TotalSize"
  
    $hash =  @{}
    $hash.Name = $vm.Name
    $hash.Disks = $hddcount
    $hash.TotalSizeGB = $TotalSize
    $object = new-object PSObject -property $hash
    $object
  } # end process
} #end Function

Notes: No, this function does not take into account any VM that has a snapshot(s) which will take up additional space, nor does this report if the disks are on different source datastores.

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.