I was listening to episode 216 of the PowerScripting Podcast recently, Hal and Jonathan were talking to vCloud Director (vCD) expert Jake Robinson and “meeting expert” (listen it will make sense) Damian Karlson, it was a great show, very funny and I highly recommend you listen here: http://powerscripting.wordpress.com/2013/02/26/episode-216-jake-robinson-and-damian-karlson-talk-powercli/
Anyway, they were talking about relating vCD objects to vCenter objects, on the show they said it couldn’t be done without matching an ID and writing a custom function, this used to be the case but now I wanted to show a few cool things from PowerCLI which allows us to use a parameter called –RelatedObject to take away all the hard work from the matching IDs, Datastore IDs, Network IDs etc.
Word of warning!
Just so you are aware, whilst VMware do provide a method for relating objects between vCD and vSphere go careful where you use it, whilst you would theoretically be able to get a cloud VM and relate this to a vSphere VM and then go on in your script to alter the VM or do some other kind of action on it I would not do this. vCD needs to know about the changes you make or you may get strange unsupported results. Generally I would stick to using this for cool reporting scripts.
With the RelatedObject parameter on some of the PowerCLI cmdlets, you can retrieve vSphere inventory objects and vSphere PowerCLI view objects from cloud resources, what’s more is that we even let you pipeline these cmdlets together to get the results. The use of these cmdlets allowing you to relate the information between the two applications allows for automation, reporting, and troubleshooting options for provider administrators and gives us an easy way to retrieve data from both applications in the same interface. Exactly what PowerShell was designed for!
The list of cmdlets which you can use with this parameter can be seen below, you will also notice that this parameter exists in the VMware Distributed Switch snapin as well:
Of course for these to work you will need to connect to vCenter with the Connect-VIServer cmdlet and in the same session connect to the vCloud Director session with Connect-CIServer, bear in mind that you may have multiple vCenters backing your vCD environment so a connection will need to be made to all of these.
Retrieving vSphere Objects from vCloud Director Resources
Provider administrators can use the RelatedObject parameter of vSphere PowerCLI cmdlets to retrieve vSphere inventory objects from vCloud Director objects. Passing the retrieved objects to the cmdlets of the VMware.VimAutomation.Core and VMware.VimAutomation.VDS snap-ins easily allows for the related object to be returned.
The following table shows which objects are currently supported:
Here is an example of this working:
Retrieving vSphere Views from vCloud Director Views
For the administrators with advanced knowledge and understanding of .NET Framework, vSphere PowerCLI, PowerShell scripting, and vSphere and vCloud APIs or if you are familiar with using the Get-View Cmdlet and Get-CIView Cmdlet you can retrieve vSphere PowerCLI views from vCloud Director PowerCLI views with the Get-CIView and Get-View cmdlets.
The following table shows which supported vSphere views you can retrieve from views:
Here are a few examples of this working:
hey and backwards? from vcenter vm get a vcloud vm?
how? can i list VM in vcd with Correspondence vSpherehost using Powercli
Hi , I am trying to get all the OrgVDCs Name and VMCount in them for particular vcloud . What query should I write to get them?
I would like to be able to get a complete list of all VMs in the vCloud infrastructure complete with their vCenter details e.g.
Get-CIVM | Get-CIView | Get-View
Get-CIVM -Name ‘MyVM’ | Get-CIView | Get-View
Is this possible or is there an alternative solution ?
Did you ever figure this out?
Using PowerCLI I am trying to add a VM to a vCloud vApp using a vCloud Template. But there is no New-CIVM (just New-VM) so I don’t know how to do this due to the vCloud objects != vCenter objects. Naively trying to use a vCloud template and a vCloud vApp gets this error:
New-VM : Cannot bind parameter ‘Template’. Cannot convert the “myvapptemplate” value of type “VMware.VimAutomation.Cloud.Impl.V1.CIVAppTemplateImpl”
to type “VMware.VimAutomation.ViCore.Types.V1.Inventory.Template”.
Can you explain how this can be done?