For some organizations, after a VM has been provisioned, it is customary to send a notification (email, slack, etc) to their end users with login credentials including the URL for the vSphere UI.
Typically, the provided URL is just the vCenter Server base URL and end users would then have to login and navigate to their specific VM(s) within the vSphere Inventory. A question was brought up on whether a better end user experience could be provided to their internal users? They were interested in providing their end users with a specific URL link that would take them directly to their VM, which they can also bookmark for future uses.
Furthermore, the customer was also interested in generating the URL programmatically, so that it can be incorporated into their existing provisioning workflows.
This can easily be achieved as each inventory object in the vSphere UI has a unique URL. For the purpose of this blog post, I will primarily be focusing on the VM inventory object, which can exists under the Hosts/Clusters view or VM/VM Templates view, but the concept will apply to other vSphere Inventory objects.
Under the Hosts/Clusters view, the URL for a VM would look like the following: https://vcsa.primp-industries.local/ui/app/vm;nav=h/urn:vmomi:VirtualMachine:vm-40043:056a402b-2b3d-4f74-93f7-fa818adff697/summary
Under the VM/VM Template view, the URL for a VM would look like the following: https://vcsa.primp-industries.local/ui/app/vm;nav=v/urn:vmomi:VirtualMachine:vm-40043:056a402b-2b3d-4f74-93f7-fa818adff697/summary
As you can see from both URLs above, the only difference is the "nav=" key that specifies whether the view is in the Hosts/Clusters (h) or VM/VM Templates (v) and the rest of the URL is the same including the VM Managed Object Reference (MoRef) ID in blue and the vCenter Server Instance UUID in orange.
With all of this information, we can easily automate the generation of the URL for a specific VM within the vSphere UI. To demonstrate this, we will be using the vSphere API and consuming that through PowerCLI with the following snippet:
$vmName = "Rocky-Linux-9" $uiView = "v" $vcHostname = $global:DefaultVIServer.name $vcInstanceUUID = $global:DefaultVIServer.InstanceUuid $vmId = ((Get-VM $vmName).id).replace("VirtualMachine-","VirtualMachine:") Write-Host "https://${vcHostname}/ui/app/vm;nav=${uiView}/urn:vmomi:${vmId}:${vcInstanceUUID}/summary"
Note: Users will still need to login to vCenter Server even with the direct link to their VM and if they do not have the appropriate permissions, they will not be able to view or do anything.
henketh says
Where do I find the "VM Managed Object Reference (MoRef) ID and the vCenter Server Instance UUID" for a specific VM?
William Lam says
Did you take a look at the blog post, the details are there 🙂