In this article, we can see an overview of how to uniquely identify a virtual machine in both a vSphere vCenter (VC) and vCloud Director (vCD) environment.
The script will help relate the virtual machine information between vCD and VC environments. For this to work correctly you will need to connect to the vCD server and then each VC listed in the resources section as shown below:
Connect-VIServer -Server ("eastcoast-vcenter", "westcoast-vcenter") -User Administrator -Password "Pa$$w0rd"
Connect-CIServer -Server MyvCDInstance -User Administrator -Password "Pa$$w0rd"
Foreach ($VM in Get-CIVM) {
$VM | Select Name,`
@{N="VM MoRef";E={$VM.ExtensionData.VCloudExtension[0].Any[0].VmVimObjectRef.MoRef}}, `
@{N="VM InstanceUUID";E={((Get-View "VirtualMachine-$($VM.ExtensionData.VCloudExtension[0].Any[0].VmVimObjectRef.MoRef)") | Where {$_.Name -match (($VM.Id).trim("urn:vcloud:vm:")) }).Config.InstanceUuid}}, `
@{N="vCenter Name";E={$VM.Extensiondata.vCloudExtension[0].Any[0].VmVimObjectRef.VimServerRef.name}}, `
@{N="vCenter InstanceUUID";E={((Get-CIView -Id $VM.Extensiondata.vCloudExtension[0].Any[0].VmVimObjectRef.VimServerRef.href).Uuid)}}
}
The output will be similar to the below:
Name : MyVM1
VM MoRef : vm-14
VM InstanceUUID : 501b8bde-95da-472a-4d2d-9d97ea394bbc
vCenter Name : westcoast-vcenter
vCenter InstanceUUID : 9B6C7A60-C60F-4C1D-A607-0A0CFA2C2D5A
Name : MyVM2
VM MoRef : vm-14
VM InstanceUUID : 502fb1ca-e9b8-82ae-3f9f-4a3ba85f081d
vCenter Name : eastcoast-vcenter
vCenter InstanceUUID : 63D30391-44E2-447E-A709-9DD1241C3DCC