WilliamLam.com

  • About
    • About
    • Privacy
  • VMware Cloud Foundation
  • VKS
  • Homelab
    • Resources
    • Nested Virtualization
  • VMware Nostalgia
  • Apple
You are here: Home / Automation / How to automate vSphere MOB operations using PowerShell?

How to automate vSphere MOB operations using PowerShell?

07.13.2016 by William Lam // 5 Comments

A couple of weeks back I was investigating something that involved the use of the vSphere Managed Object Browser (MOB) and I needed to automate a particular operation. For those of you not familiar with the vSphere MOB, it is a UI debugging tool that allows you to visualize and invoke vSphere APIs using just a web browser. The vSphere MOB is available on both vCenter Server and ESXi and uses the underlying vSphere API. Outside of learning about the vSphere APIs and potentially for troubleshooting purposes, there really is no good reason to be directly interacting with the vSphere MOB on a regular basis. Customers can use any one of the many vSphere SDK/CLIs to easily automate and interact with the vSphere API.

Having said that, there may be cases where you might want to invoke a specific operation using the vSphere MOB, such as private API for example. Obviously, using any private/internal APIs is not officially supported by VMware and their use will be at your own risk. Nonetheless, I had a specific operation that I needed to call from the vSphere MOB and wanted to do so using PowerShell. Several years back I had demonstrated how you could invoke the vSphere MOB using Python but I could not find any PowerShell examples that actually worked. I figured this would be a good learning opportunity for myself and probably something I or others could benefit in the future.

To provide a concrete example, I will be invoking a supported vSphere API called the QueryOptions which is used for accessing either a vCenter Server or ESXi Advanced Settings. For our example, I will be connecting to the vCenter Server's MOB and will be querying for a specific vCenter Server Advanced Setting. If we were to do this manually in the vSphere MOB, we would first open a web browser and login to the following URL: https://[VC-SERVER]/mob/?moid=VpxSettings&method=queryView

automate-vsphere-mob-using-powercli
If you wanted to see all advanced settings, you would leave the "name" parameter blank. For our example, we will query for the VirtualCenter.InstanceName property as shown in the screenshot above and then click on the "Invoke Method" to execute the vSphere API operation. If successful, it should display the results which in our case is the IP Address of my vCenter Server. Pretty straight forward vSphere MOB example. OK, onto automating this from PowerShell. I have created a sample PowerShell script called automate-vsphere-mob.ps1 which you will need to edit and provide your vCenter Server Hostname/IP Address and the vCenter Server credentials (can be read-only) since we are not performing any write operations.

Here are some more specific details on what is happening in the script for those interested:

  1. Authenticate to the vSphere MOB URL that you wish to invoke using an HTTP GET operation and storing the session into a variable named vmware (Line 28-29)
  2. Extract the hidden vmware-session-nonce property used to prevent Cross-Site Request Forgery (CSRF) (Line 31-40)
  3. Create the body request which must include the vmware-session-nounce property along with the vSphere API payload (Line 42-45)
  4. Invoke the actual vSphere API call using an HTTP POST along with the existing session from Step 1 and body payload
  5. Process the results (this will be specific to API call) and profit! (Line 50-59)

If you now run the script, you will see that the result is exactly what we saw from interactively using the vSphere MOB. Hopefully this will be useful for anyone who may have a need to automate against the vSphere MOB. For those curious on what I was investigating with the vSphere MOB, stay tuned for more details 🙂

More from my site

  • An update on how to retrieve useful information from a vSphere login?
  • How to easily disable vMotion & Cross vCenter vMotion for a particular Virtual Machine?
  • How To Initiate a Wipe & Shrink Operation On an SE Sparse Based Disk
  • What's new in the vSphere 4.1 MOB
  • How to unregister vCenter plugin/extension using the MOB

Categories // Automation, ESXi, PowerCLI, vSphere Tags // Managed Object Browser, mob, PowerCLI, powershell, vSphere API, vSphere MOB

Comments

  1. *protectedAlexey says

    07/14/2016 at 9:50 am

    It's very interesting, thank you.

    Reply
  2. *protectedAlexey Goncharov says

    08/15/2018 at 5:34 pm

    Hi William,
    I am looking for any ways to add internal ESXi/vCenter build version into a host settings. After reading the post checked the MOB on the vCenter and found next property:

    Parent Managed Object ID: ServiceInstance
    Property Path: content.about

    localeBuild string "000"

    Which is sound absolutely as what I need. But I can't find the way to change it. Can you give a hint?

    Cheers,
    Alex.

    Reply
  3. *protectedNagamohan says

    01/28/2021 at 6:27 am

    How to assign a user role to ESXI to have only MOB login privillages ?

    Reply
    • William Lam says

      01/28/2021 at 7:54 am

      There’s no such thing as MOB priv. As article outlines, it’s just another interface to vSphere API. If you have perm to login to ESXi UI, you have access to MOB

      Reply
  4. *protectedChad Abeln says

    04/16/2021 at 7:03 am

    Thanks for all that you do William! This helped me to automate creating a SINK port for the NSX standalone client required for L2VPN. Love your work!

    Reply

Thanks for the comment!Cancel 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

 

Loading Comments...