VMware Cloud Community
TryllZ
Expert
Expert
Jump to solution

Setting ESXi FQDN as the hostname..

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.

vServer-2019-09-25-09-01-07.png

Thank You

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

10 Replies
LucD
Leadership
Leadership
Jump to solution

What is the problem when you do the following?

$esxName = '192.168.1.1'

$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

Reply
0 Kudos
Alex_Romeo
Leadership
Leadership
Jump to solution

Hi,

this post may be useful to you:

or

ARomeo

Blog: https://www.aleadmin.it/
TryllZ
Expert
Expert
Jump to solution

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

Reply
0 Kudos
TryllZ
Expert
Expert
Jump to solution

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.

vServer-2019-09-25-16-03-03.png

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The hash table key is fqdn.

Like this

$esxName = '192.168.2.21'

$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

Reply
0 Kudos
TryllZ
Expert
Expert
Jump to solution

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)

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

No, I'm afraid that is a slight inconsistency we will have to live with.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
TryllZ
Expert
Expert
Jump to solution

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.

vServer-2019-09-25-16-03-03.png

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

TryllZ
Expert
Expert
Jump to solution

Appreciate bringing that up I totally forgot that.

Thanks..

Reply
0 Kudos