There was an interesting article this morning by my colleague Dave Hill about Looking up Managed Object Reference (MoRef) in vCenter Server, which references a VMware KB article showing you how to use vSphere MOB to find MoRef IDs.

A Managed Object Reference ID also known just as MoRef ID is a unique value that is generated by the vCenter Server and is guaranteed to be unique for a given entity in a single vCenter instance. Steve Jin has a great article going into detail about MoRef's, that you should check out here. MoRef ID's are not only used in vSphere, but they can also be referenced in other VMware products such as vCD (vCloud Director) or SRM to name a few or even by 3rd party/custom tools as a way to uniquely track objects within vCenter.

Using the vSphere MOB is one way of retrieving the MoRef ID, but of course this can be tedious if you are trying to locate MoRef's for multiple entities, in multiple vCenters. I decided to write a quick vSphere SDK for Perl script called that allows a users to quickly query for a variety of Managed Objects (VM,Host,Cluster,Datacenter,Resource Pool,Network, Distributed vSwitch, Folder, vApp and Datastore) in a vCenter Server.

I also noted earlier, MoRef ID is only unique within a vCenter instance, so how do you track these objects across multiple vCenters? Well, VMware introduced a new property called instanceUUID (128 bit UUID) which is unique for a given vCenter Server and you can use this along with the MoRef ID to uniquely track objects across multiple vCenters and the script automatically outputs this value for any query.

Note: There have been some optimization in the latest vSphere SDK for Perl 5.0, it is recommended you use the latest version which is backwards compatible with vSphere 3.x and 4.x

The script requires two parameters:

  • type - The type of managed object
  • name - The name of the object as seen in vCenter Server

Here is an example querying for a Virtual Machine:

Here is an example querying for a Host:

Here is an example querying for a Cluster:

Here is an example querying for a Datacenter:

Here is an example querying for a Resource Pool:

Here is an example querying for a Network (Portgroup):

Here is an example querying for a Distributed vSwitch:

Here is an example querying for a Folder:

Here is an example querying for a vApp:

Here is an example querying for a Datastore:

16 thoughts on “vSphere MoRef (Managed Object Reference) ID Finder Script

  1. Nice work William, is the 5.1 version of vSphere SDK for Perl supported?
    I keep getting the below error after it reports the vCenterInstanceUUID:

    Use of uninitialized value in concatenation (.) or string at C:\ line 88.
    Can’t call method “value” on an undefined value at c:\ line 88.

    • Yes this works on 5.1 as well, make sure you’re typing in the correct entity name (display name) and type, else it will not be able to find the object and hence it would print undefined value.

  2. how to retrive the uuid of the resourcepool from the data center
    ??? using vi java api…plz help me

  3. Hi William, great work! I added support to get the MoRef ID of datastore clusters… this is the diff
    < help => “vm|host|cluster|datacenter|rp|network|dvs|folder|vapp|datastore”,

    > help => “vm|host|cluster|datacenter|rp|network|dvs|folder|vapp|datastore|dsCluster”,
    < 'datastore' => ‘Datastore’

    > ‘datastore’ => ‘Datastore’,
    > ‘dsCluster’ => ‘StoragePod’


  4. Thanks for the great write up William! Do you know if the MoRef ID is guaranteed to be *historically* unique in a single vSphere server? If a VM is deleted will another VM eventually re-use the old MoRef ID? I have seen a lot of assumptions in blogs/forums, and hoped you might have a definitive answer.

  5. Thank you once again! If I am going way off topic, I apologize. A response of “Look elsewhere” is totally acceptable. 🙂

    I am waiting for updates on latestPage of an EventHistoryCollector for a set of VM events under the root folder, but cannot see how to include the VM InstanceUUID of each event in those updates. If you know of an example, I’d appreciate a redirect. If not, I’ll continue my search.

    • Yes, you can it connecting directly to ESXi host IF you plan to work with it directly. If you have vCenter Server, then it’ll have a diff MoRef ID and you’ll need to use the API

Thanks for the comment!