Hi,
I'm trying to set the FQDN as the hostname for ESXi hosts in vCenter.
I have the following command :
$esxcli = Get-esxcli -vmhost 192.168.2.21
$getname = $esxcli.system.hostname.get() | select Fullyqualifieddomainname
Now when I check the variable it has a value that I cannot set as the hostname which is :
write-host $getname
@{FullyQualifiedDomainName=esxi1.v.lab}
Is there an alternate way to this.
Currently the ESXi hosts appear with their IP addresses as their display names in vCenter.
Thank You
Are you sure on that on the VCSA, the FQDN of the ESXi node can be resolved?
If not, the IP address will be used to register the ESXi node.
---------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
What is the problem when you do the following?
$esxcli = Get-EsxCli -VMHost $esxName -V2
$hostName = @{
domain = 'mydomain.lab'
host = 'MyEsx'
}
$esxcli.system.hostname.set.Invoke($hostname)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
this post may be useful to you:
or
ARomeo
This has been resolved.
Since the value returned by $getname is in Hash table the key value is retrieved by using $getname.FullyQualifiedDomainName
Thank You
So my attempt did not work as it does NOT replace the existing value of Hostname but adds to it in vCenter.
I tried the code you mentioned with -V2 as follows albeit with some changes since in the code shown the values are manually fed while I'm trying to retrieve the FQDN value and set it as the display name of the esxi host in vcenter. Unsure why the error below as the result is of type hash table.
$esxcli = get-esxcli -vmhost 192.168.2.21 -v2
$getname = $esxcli.system.hostname.get.invoke() | select FullyQualifiedDomainName
write-host $getname
@{FullyQualifiedDomainName=esxi1.v.lab}
$esxcli.system.hostname.get.invoke($getname)
for which I receive the error
If specified, the arguments parameter must contain a single value of type Hashtable.
At line:1 char:1
+ $esxcli.system.hostname.set.invoke($getname.FullyQualifiedDomainName)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException
Another thing I noticed is in vCenter the ESXi host already has the hostname then why does it not display that rather than the IP address.
The hash table key is fqdn.
Like this
$esxcli = Get-EsxCli -VMHost $esxName -V2
$hostName = @{
fqdn = 'esxi1.v.lab'
}
$esxcli.system.hostname.set.Invoke($hostname)
An explanation for the IP in the vCenter, instead of the FQDN, can be found in Re: vCenter IP showing instead of hostname
To solve that disconnect/connect the ESXi node (with the FQDN of course)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for clarifying it did help a lot.
I understand the FQDN is the hash table key, what I'm trying to understand is that the result from my code
$getname = $esxcli.system.hostname.get.invoke() | select FullyQualifiedDomainName
write-host $getname
@{FullyQualifiedDomainName=esxi1.v.lab}
is already in the hash table format, shouldn't it work here
$esxcli.system.hostname.get.invoke($getname)
No, I'm afraid that is a slight inconsistency we will have to live with.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for all the help.
So finally got to add the hostname, however, even after removing the host, restarting, and re-adding it to vCenter no change occurred.
Just to be clear I'm trying to show the host name of the ESXi instead of the ESXi's IP address in the vCenter cluster.
And that the IP address are manually entered and so the ESXi host is not picking the FQDN name from the windows DNS entry.
Are you sure on that on the VCSA, the FQDN of the ESXi node can be resolved?
If not, the IP address will be used to register the ESXi node.
---------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Appreciate bringing that up I totally forgot that.
Thanks..