TryllZ
Hot Shot
Hot Shot

Setting ESXi FQDN as the hostname..

Jump to solution

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

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

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

0 Kudos
Alex_Romeo
Leadership
Leadership

Hi,

this post may be useful to you:

or

ARomeo

Blog: https://www.aleadmin.it/
TryllZ
Hot Shot
Hot Shot

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

0 Kudos
TryllZ
Hot Shot
Hot Shot

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

0 Kudos
LucD
Leadership
Leadership

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

0 Kudos
TryllZ
Hot Shot
Hot Shot

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)

0 Kudos
LucD
Leadership
Leadership

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


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

0 Kudos
TryllZ
Hot Shot
Hot Shot

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

0 Kudos
LucD
Leadership
Leadership

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
Hot Shot
Hot Shot

Appreciate bringing that up I totally forgot that.

Thanks..

0 Kudos