VMware {code} Community
pascuzzi
Contributor
Contributor

Help getting started with FindByUUID

I am porting some legacy C# code that powers on and off a VM buy its uuid. I would like to use the findbyUUID to get me the VM. The document says that you do not need to provide the DataCenter. When I try the following code snipp it an error is thrown

ManagedObjectReference dc= null;

ManagedObjectReference vmMoRef = _service.FindByUuid(ServiceRef, dc ,vmGUID, true);

Just seeing If anyone has any ideas or a C# code sample using findBYUUID without a datacenter managed object reference

Thanks

0 Kudos
3 Replies
njain
Expert
Expert

Hi,

In the above code snippet, the parameter you pass in as datacenter is a MOR with null value. This is the reason for the error that you see. You would need to pass a null value for second parameter (datacenter) to search the entire inventory.

Replace it with the following code snippet and it should be working:

// Assuming "ServiceRef" holds a reference to the SearchIndex

ManagedObjectReference vmMoRef = _service.FindByUuid(ServiceRef, null, vmGUID, true);

Hope the above information helps.

Regards,

Neha

0 Kudos
pascuzzi
Contributor
Contributor

Nope I am still having problems. Do you have a full sample code?

0 Kudos
njain
Expert
Expert

Attached is a small C# sample for powering ON a virtual machine. This sample takes in the UUID of the VM as an input parameter that you wish to power ON. It then finds the MOR of this VM using the FindByUuid API and invokes the PowerOnVM_Task method. Hope this sample will help you in sorting out the issues.

Regards,

Neha

0 Kudos