With an increasing number of customers enabling the vSphere with Tanzu capability, which is included in both VMware vSphere Foundation (VVF) and VMware Cloud Foundation (VCF), more and more Virtual Machines will be deployed using the more modern approach of declarative provisioning using the powerful VM Service feature.
When using the vSphere UI, you can easily distinguish between a vSphere with Tanzu managed VM from a traditional VM by checking whether it is provisioned within a vSphere Namespace or whether it contains the "Developer Managed" label as shown in the screenshot above.
However, how do you identify a vSphere with Tanzu managed VM when using the vSphere API for Automation purposes?
The fastest way to check whether a VM is associated with a vSphere Namespace can be accomplished by inspecting the parent Resource Pool of a VM, which is how a vSphere Namespace is implemented on the backend. There is a namespace property that is a part of the Resource Pool object and if this property is not empty, then it is a VM that is managed by vSphere with Tanzu and the namespace property will contain the name of the vSphere Namespace.
Using PowerCLI, we can easily demonstrate how to access this property using the vSphere API by running the following command for a particular VM:
(Get-VM "rocky9-02").ResourcePool.ExtensionData.Namespace
As you can see from the output, our VM named "rocky9-02" is a vSphere Managed VM because the namespace property is NOT empty AND we can see it has been provisioned under the "prod-02" vSphere Namespace, which matches what we see in the vSphere UI screenshot above.
If we attempt to run the command above for a non-vSphere with Tanzu VM, the output will simply be empty or null.
Thanks for the comment!