Hi.
There was already a similar topic.
https://community.broadcom.com/vmware-cloud-foundation/discussion/how-to-get-esxi-host-name-within-running-vm#bm7638469a-5c82-42e1-86ff-94899cb3f74a
It is possible though to set a custom attribute on the VM object in vCenter and then query this from within the the OS of the virtual machine.
For example:
$vmView = GET-VM -Name 'Vm_Name' | Get-View
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$gInfo = New-Object VMware.Vim.optionvalue
$ginfo.Key=”guestinfo.hostname”
$gInfo.Value=$vmView.Name
$vmConfigSpec.extraconfig += $gInfo
$vmView.ReconfigVM($vmConfigSpec)
Once this is set, it is possible to query it within the VM, using the VM tools and the following command:
vmtoolsd -–cmd “info-get guestinfo.hostname”