Managing VCD VM Disks from PowerCLI / PowerShell

One of the issues I come up against every now and again is when a customer asks how they can automate some functionality in our VMware Cloud Director (VCD) cloud platform and I think ‘that should be easy in PowerShell / PowerCLI’ only to find out that the necessary cmdlets to accomplish the activity aren’t present.

Such was this case where a customer needed a way to manage the internal hard disks attached to some of their virtual machines from code. While I typically use the awesome Terraform provider for VCD these days which can easily cope with this scenario, in this case there was a requirement to manage VM hard disks from within existing PowerShell scripts.

So, as usual, I set about writing an extension module for PowerCLI to add this functionality. I also wanted to challenge myself to write some ‘better’ PowerShell code that would do automatic detection of VCD API versions (and so work with future releases and API versions without having to be updated each time). I also wanted to handle XML from the VCD API ‘properly’ – using the PowerShell XML methods, namespaces and properties and avoid simply ‘string bashing’ XML fragments together.

The result of all of this is a module I’ve published today on Github and in PowerShell Gallery ‘CIVMDisks’. I’ve written up reasonably comprehensive details and examples in the Github repository so rather than repeat all of that here I’ll just include a link.

The module contains 4 cmdlets:

Get-CIVMDisk Get the details of existing internal disks on a VCD VM
Add-CIVMDisk Add a new disk (and controller if required) to a VCD VM
Update-CIVMDiskSize Resize an existing VCD VM disk (only increases permitted)
Remove-CIVMDisk Remove/delete a disk from a VCD VM

As always, please test properly in a test/dev environment before using this in production, and feel free to log issues and/or PRs against the github repo if you find problems.

I also want to thank Eugene Burhovetsky from the VMware Cloud Providers Slack channel for doing some early testing and helping catch a bug in handling invalid SSL certificates for me.

Hopefully this will be useful for some of you.

Jon.

Tagged , , , . Bookmark the permalink.

5 Responses to Managing VCD VM Disks from PowerCLI / PowerShell

  1. Stephen Gibbons says:

    Brilliant. Perfect for what I needed.

    Do you have anything that can return the name of, size of and usage/free of Storage Profiles in GB ?

    API version is 35
    I think I was using the SIOC module until they upgraded recently

  2. Jurgen says:

    Hi Jon,

    I Tried your module .3 but I get ths error
    Write-Error: Error retrieving VM properties from VCD API, exiting.

    Your module is a bit old, maybe there is an update needed or is there another way to add a disk using powercli?

    • Jon Waite says:

      Hi Jurgen, I really need to get around to fixing up more of my old modules, but your message prompted me to focus on this one – so I’ve updated and fixed it for the latest VCD versions. You should be able to ‘Update-Module CIVMDisks’ from PowerShell to get the new version which should now work. If you still have issues please raise an issue against the Github repository at https://github.com/jondwaite/civmdisks and I’ll see what I can do to get it working for you.
      Thanks, Jon.

  3. Hinaki says:

    I’m trying to use this today but also getting

    Write-Error: Error retrieving VM properties from VCD API, exiting.

    Any ideas what i need to change to make it work? 🙂

  4. Roy says:

    Hello Jan,

    Our team upgraded to VMWare Virtual Cloud Director 10.4.1 recently and it seems to have affected this module. Ever since the upgrade we are also getting the “Write-Error: Error retrieving VM properties from VCD API, exiting.” error on the execution of the line below:
    $vm | Add-CIVMDisk -DiskSize $VMDiskSize

    $vm returns the VM propeties with expected results as obtained by “$vm = Get-CIVM -Name $VMHostname”.

    Hope this helps!

Leave a Reply

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

20 − thirteen =