Home > Blogs > VMware PowerCLI Blog


Retrieving vCloud Director VM Hard Disk size

I was asked recently if we were able to retrieve the disk space of a VM in vCloud Director through PowerCLI, on checking this I found that it is not currently part of the CIVM object and also there is currently no Get-HardDisk cmdlet equivalent like in the vSphere snapin.

After looking through the REST API Reference Documentation –> User Operations I found an entry for the VM VirtualHardwareSection  and specifically the disks which can be found as can be seen here: GET /vApp/{id}/virtualHardwareSection/disks

The virtualhardwaresection is easily accessed via PowerCLI using the extensiondata property which allows access to the back end API, I could then find my disk properties by filtering on the description of Hard Disk as in the example below:

(Get-VM MyCloudVM).ExtensionData.getvirtualhardwaresection().Item | Where { $_.Description -like “Hard Disk”}

Now I had the hard disk I noticed that part of the information was the capacity as highlighted below:image

With this information I could then find the capacity of the disk and add the information I needed into more of a friendly PowerShell property to the Hard Disk object.

So tying this all back together we could easily use the .ExtensionData reference to create our own Advanced PowerShell function to return the hard disk information for any CIVM.

Example

The following shows an example of how to use this new function and the output, this of course can also be used to export into CSV/HTML/Text or any other format PowerShell can be used with, it is also great for reporting on where the disk space in your cloud is being used!

image

The Code

Function Get-CIVMHardDisk {
Param (
[Parameter(Mandatory=$True,ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)]
$CIVM
)
Process {
$AllHDD = $CIVM.ExtensionData.getvirtualhardwaresection().Item | Where { $_.Description -like “Hard Disk”}
$HDInfo = @()
Foreach ($HD in $AllHDD) {
$HD | Add-Member -MemberType NoteProperty -Name “Capacity” -Value $HD.HostResource[0].AnyAttr[0].”#text”
$HD | Add-Member -MemberType NoteProperty -Name “VMName” -Value $CIVM.Name
$HDInfo += $HD
}
$HDInfo
}

}

This entry was posted in Extensions, vCloud and tagged , , , on by .
Alan Renouf

About Alan Renouf

Alan Renouf is a Product Line Manager at VMware focusing on API’s, SDK’s and CLI’s, He is responsible for providing the architects and operators of private and public cloud infrastructure with the toolkits/frameworks and command-line interfaces they require to build a fully automated software-defined datacenter.

Alan is a frequent blogger at http://blogs.vmware.com/PowerCLI a book author and has a personal blog at http://virtu-al.net.

You can follow Alan on twitter as @alanrenouf.

5 thoughts on “Retrieving vCloud Director VM Hard Disk size

  1. Pingback: Retrieving vCloud Director VM Hard Disk size

  2. Sander van den Brom

    Cheers!
    Just what i needed.

    Get-CIVM | where name -Like “NL-AM*” | Get-CIVMHardDisk | select VMName, ElementName, Capacity

    Reply
  3. Jon Waite

    I know it’s an old post, but still very useful – thanks Alan.

    I had a recent requirement to extend this functionality for a customer who consumes multiple different storage tiers from our cloud platform and wanted to see not just which disks were attached to each VM, but which storage tiers these were on too (since vCloud Director 8.xx and later allow these to be different). I’ve written up how I did this at: http://kiwicloud.ninja/2017/01/detailed-vm-storage-information-in-vcloud-director/ in case this is of use to anyone else.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

*