VMware vCloud Powershell (Part 1: Get-vCloud)

November 4, 2010 by Jake Robinson
VMware vCloud Director (and vCloud Datacenter) is the answer to a lot of needs. It gives the VMware Administrator the ability to grant more control to different departments (or orgs), provide better insight into how orgs are using resources, and the ability to control a worldwide infrastructure from a central management system.
There are, of course, caveats. vCloud Director, like Lab Manager, tends to get a little fussy when we do things to infrastructure behind it’s back. You must make sure to perform through the vCloud Director interface, or at least shut something down through the interface first, or you might catch some slack.
The web interface is nice, but unfortunately it doesn’t like my browser of choice. I grimace every time I have to fire up Internet Explorer to get into vCloud Director. Once I am in though, I completely forget about the browser and go about my tasks. That is, until I have to navigate the foreign interface. "Where was that stinkin’ network setting?!"
Sesame StreetOf course with every new toy comes a new API. The vCloud API, in this case. I imagine an episode of Sesame Street with "The Count" counting all of the VMware APIs: "One API, ah ah ah…Two APIs, ah ah ah," but I digress.
I very rarely open the vSphere client anymore. I have been using PowerCLI since Powershell v2 arrived and haven’t looked back. Now, once in a while I’ll pop in there to look at a pretty graph, or to visually verify what someone else is seeing in the interface, but other than that, I do everything through PowerCLI.
PowerCLI still works for the underlying Infrastructure in a vCD environment, but You’re not allowed to do anything too useful without first having to do something in vCD.
So what is a command-line loving Engineer to do?
The vCloud API is REST based which was the biggest hurdle for me. I had to write some sort of pseudo-cmdlet to talk to vCloud Director through HTTPs. Now, I am no stranger to software development, but this was my first endeavor in the world of REST and web requests in .NET, for that matter.
The requirements I had for this first Proof of Concept were:
1. It must function like powerCLI. 
2. It must not rely on anything besides the built-in .NET libraries.
I wrote vCloud-Powershell as advanced functions, which means they work close if not exactly to cmdlets.
The first cmdlets I wrote were Connect-vCloud (obviously), Get-vCloudURI, and Post-vCloudURI. "Get" and "Post" are directly related to the type of HTTP request that the cmdlet performs against the vCloud API. Generally if you are making a change, you will be using the Post command, and if you are retrieving info, you will be using the Get command. Easy enough, right? I’ll also add that Get-vCloudURI is much like PowerCLI’s Get-View, which doesn’t hold anything back. :D
These functions, when given a URI, enabled me to look at the raw response and content that the vCloud API was returning. These commands are the interface for all of my other cmdlets to go through.
The next set I wrote were Disconnect-vCloud, Get-vCloudvDC, Get-vCloudvApp, and Get-vCloudVM. These do not do any direct REST communication, but use the Get and Post commands to get the raw content from the vCloud, Prune, format, and return as a PSObject.

Example usage

First, import the vCloud functions:

. .vCloud-functions.ps1

Connect to the server:

Connect-vCloud "https://vCloudAPIserver/api/v1.0/" -username "myUser" -org "MyOrg" -password "supersecretpassword"

List vDC info:


List all vApps in all vDCs:

Get-vCloudVDC | Get-vCloudvApp

List all VMs containing the name "Fred"

Get-vCloudVM | where {$_.name -match "Fred"}


Now, this is point where I tell you that these are still under development. I am putting more functionality into the currently written cmdlets, as well as adding more cmdlets.
I will also say that at some point these will be deprecated in favor of whatever VMware comes up with. Until that time, I am going to keep plugging away at creating useful powershell stuff for the vCD users and tinkerers out there.
If you’re interested in helping out, have a bug to report, or would like to see something in "Part two" of this blog post, hit me up on Twitter or the comments below!

  • Alan Renouf

    Great stuff – a few initial comments if I may..

    I would use the PowerShell golden rule for naming conventions, verb-noun Something like Get-VCDblahh would be cool so you would have Get-VCDVM and Get-VCDvApp etc etc

    I am going to get some time to mess with these soon so more comments may come !

  • Jake

    Hey Alan,

    There was a great internal battle when I thought about the naming convention. :D Do I follow the rules and end up with functions like Get-vCDvDC, or do I do something more readable like Get-vCloud-vDC? In the end, I decided to do more of a verb-adjective-noun for readability. So, I completely agree with you, but I haven’t come up with something that’s not completely ugly. I am always open to suggestions and criticisms!



  • TV

    Right now it seems that User and Group creation in vCloud Director is a manual task, can the same be automated using Powershell?

  • Jake

    Hi TV,

    Yes, User and group administration is part of the vCloud API, see page 110 of the programming guide, and hit me up on twitter if you want the cmdlets added!