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.

RelatedObject Parameter

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:

Cloud Object

Retrieved vSphere Inventory Object

Example code

ProviderVdc

Datastore

Get-ProviderVdc -Name ‘MyProviderVdc’ | Get-Datastore

CIVM

VirtualMachine

Get-CIVM -Name ‘MyCloudVM’ | Get-VM

NetworkPool

VDSwitch

Get-NetworkPool -Name ‘MyNetworkPool’ | Get-VDSwitch

NetworkPool

VDPortgroup

Get-NetworkPool -Name ‘MyNetworkPool’ | Get-VDPortGroup

ExternalNetwork

VDPortgroup

Get-ExternalNetwork -Name ‘MyExternalNetwork’ | Get-VDPortGroup

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:

Share this:

Like this:

Alan Renouf has a role of Automation Frameworks Product Manager at VMware responsible for providing the architects and operators of the 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/vipowershell and has a personal blog at http://virtu-al.net. You can follow Alan on twitter as @alanrenouf.

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: