WilliamLam.com

  • About
    • About
    • Privacy
  • VMware Cloud Foundation
  • VKS
  • Homelab
    • Resources
    • Nested Virtualization
  • VMware Nostalgia
  • Apple
You are here: Home / Automation / vSphere MoRef (Managed Object Reference) ID Finder Script

vSphere MoRef (Managed Object Reference) ID Finder Script

11.25.2011 by William Lam // 20 Comments

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 moRefFinder.pl 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:

More from my site

  • When Do vSphere MoRef's Change?
  • Uniquely identifying VMs in vSphere Part 3: Enhanced Linked Mode & Cross VC-vMotion
  • Enabling/Disabling EVC using the vSphere MOB
  • Auditing vMotion Migrations
  • How to identify the origin of a vSphere login?

Categories // Automation Tags // managed object reference, mob, moref, vSphere, vsphere sdk for perl

Comments

  1. *protectedMichael says

    01/03/2013 at 6:02 pm

    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:\moRefFinder.pl line 88.
    Can't call method "value" on an undefined value at c:\moRefFinder.pl line 88.

    Reply
    • *protectedWilliam says

      01/04/2013 at 1:13 am

      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.

      Reply
    • *protectedMichael says

      01/04/2013 at 2:04 pm

      Brilliant, thanks! working great now.
      forgot that when in doubt, check for case sensitive.

      Reply
  2. *protectedAnonymous says

    01/16/2013 at 5:57 am

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

    Reply
  3. *protectedJavier Viola says

    04/16/2013 at 3:27 am

    Hi William, great work! I added support to get the MoRef ID of datastore clusters... this is the diff
    40c40
    < help => "vm|host|cluster|datacenter|rp|network|dvs|folder|vapp|datastore",
    ---
    > help => "vm|host|cluster|datacenter|rp|network|dvs|folder|vapp|datastore|dsCluster",
    68c68,69
    < 'datastore' => 'Datastore'
    ---
    > 'datastore' => 'Datastore',
    > 'dsCluster' => 'StoragePod'

    regards

    Reply
  4. *protectedMichał Czerwiński says

    05/15/2014 at 10:07 am

    Hello.

    Your Perl script is very helpfull but could You provide also Python version?

    Thanks.

    Reply
  5. *protectedJim says

    10/27/2014 at 1:24 pm

    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.

    Reply
    • lamw says

      10/27/2014 at 3:32 pm

      That's correct, a MoRef ID is guaranteed to be unique AND it can potentially re-use an old MoRef that has been recycled. I've personally seen this in environment's I've managed where the churn of VMs are quite high such as Continuous Integration/Deployments.

      Reply
      • *protectedJim says

        10/27/2014 at 3:59 pm

        Thank you for the quick reply!

        If we are going to have to resort to a UUID as a historically unique reference, is there a way to include the UUID in events from an event collector so that we do not need to store a MoRef ID to UUID mapping or query vSphere for the UUID based on the MoRef ID in the event?

        Reply
        • William Lam says

          10/27/2014 at 4:05 pm

          Yes, it's just like any other property. In the property collector spec, you specify what you're interested in. MoRef ID will always be there given it's the unique identifier and you can specify the instanceUUID if you want to use that in conjunction. If you're dealing with more than 1 VC, I would recommend giving up on the MoRef ID and concatenating VC InstanceUUID + VM InstanceUUID.

          Take a look at these two blog posts http://blogs.vmware.com/vsphere/2012/02/uniquely-identifying-virtual-machines-in-vsphere-and-vcloud-part-1-overview.html & http://blogs.vmware.com/vsphere/2012/02/uniquely-identifying-virtual-machines-in-vsphere-and-vcloud-part-2-technical.html which provides more details regarding this topic

          Reply
  6. *protectedJim says

    10/27/2014 at 7:01 pm

    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.

    Reply
  7. *protectedhotspicyramen says

    02/09/2015 at 2:39 am

    You can use vim-cmd vmsvc/getallvms to get vMid ? is it the same?

    Reply
    • William Lam says

      02/09/2015 at 4:15 am

      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

      Reply
  8. *protectedBhavya Shah says

    05/23/2019 at 1:31 pm

    Hello, what if I want the ManagedObjectReference of vCenter server itself.?
    Actually my ultimate goal is to get vcDebugInfo performance metrics using vSphere API, which wants us to pass moid for method queryperf, but as per my understanding these metrics belong to vCenter, then what should I do?

    Please help,
    Thanks.

    Reply

Trackbacks

  1. How to (quickly) match a moRef ID to a name in VMware vSphere | Danilo Chiavari says:
    03/28/2014 at 8:39 am

    […] to note that this identifier is guaranteed to be unique only within a single vCenter instance. In this article by William Lam it is explained that an additional identifier called InstanceUUID (unique for a […]

    Reply
  2. Using VMware’s Standalone Remote Console for OS X with free ESXi | Der Flounder says:
    04/18/2015 at 1:31 am

    […] Running this script developed by William Lam of virtuallyGhetto2. If you have SSH enabled on your ESXi server, connecting via SSH and running the following […]

    Reply
  3. Standalone VMRC (VM Remote Console) re-introduced in vSphere 5.5 Update 2b | virtuallyGhetto says:
    12/08/2015 at 8:26 am

    […] method accepts basic authentication using username/password, the vCenter Server address and the VM MoRef Id. Here is an example of what that would look […]

    Reply
  4. vCenter Appliance Migration Upgrade says:
    10/22/2018 at 1:25 pm

    […] Once a host with VMs gets registered to a new vCenter, all VMs will be assigned a new MoRef ID (Managed Object Reference ID), which is unique within that vCenter. There's an old blogpost by William Lam about Managed Object Reference IDs. […]

    Reply
  5. vCenter Appliance Migrations-Upgrade says:
    02/05/2019 at 9:06 am

    […] Sobald ein Host mit VMs in einem neuen vCenter registriert wird, erhalten alle VMs eine neue MoRefID (Managed Object Reference ID), die in diesem vCenter einzigartig ist. Es gibt zum Thema einen älteren Blogpost von William Lam über Managed Object Reference IDs. […]

    Reply
  6. Using VMWare Remote Console with CyberArk to connect to Virtual Machines – LM@AB says:
    04/30/2020 at 11:23 am

    […] VirtuallyGhetto – "vSphere MoRef (Managed Object Reference) ID Finder Script" […]

    Reply

Leave a Reply to Standalone VMRC (VM Remote Console) re-introduced in vSphere 5.5 Update 2b | virtuallyGhettoCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Search

Thank Author

Author

William is Distinguished Platform Engineering Architect in the VMware Cloud Foundation (VCF) Division at Broadcom. His primary focus is helping customers and partners build, run and operate a modern Private Cloud using the VMware Cloud Foundation (VCF) platform.

Connect

  • Bluesky
  • Email
  • GitHub
  • LinkedIn
  • Mastodon
  • Reddit
  • RSS
  • Twitter
  • Vimeo

Recent

  • Programmatically accessing the Broadcom Compatibility Guide (BCG) 05/06/2025
  • Quick Tip - Validating Broadcom Download Token  05/01/2025
  • Supported chipsets for the USB Network Native Driver for ESXi Fling 04/23/2025
  • vCenter Identity Federation with Authelia 04/16/2025
  • vCenter Server Identity Federation with Kanidm 04/10/2025

Advertisment

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy

Copyright WilliamLam.com © 2025