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.
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
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?
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.