VMware Cloud Community
ChandanNagaraja
Contributor
Contributor

Modify Hostname using PowerCLI

Hi All,

I am creating an Script for Commissioning the newly build DELL ScaleIO HCI based Ready nodes to Production. I am stuck at modifying the "Hostname" and "Domain Name" after initial build which means it is standalone, Not added to vCenter yet.

1. Dell Customized ESXi 6.5 U2 is deployed

2.  "Hostname" in "Default TCP/IP Stack"  Edit Settings has to be re-named through PowerCLI

3. I get the place where parameter exists which is Get-VMHost  -Name " IP Address " | fl

4. Name & NetworkInfo needs to be renamed.

Please let me know if this can be performed. Tried with "Set-VMHost" and creating an variable from "Get-ESXCli" output and no luck.

Thanks in advance

Reply
0 Kudos
3 Replies
LucD
Leadership
Leadership

For my correct understanding, you want to change the DNS settings (hostname & domain) of the Default TCP/IP Stack?

stack.jpg


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

Reply
0 Kudos
ChandanNagaraja
Contributor
Contributor

Yes, You are right LucD. Attached image

Reply
0 Kudos
LucD
Leadership
Leadership

Try something like this.
You have to change the variables in the first 3 lines.

In $esxName use the name or IP that you use to currently connect with the Web Client.

The $hostName is the new hostname, no domain added.

The $domainName is the new domain.

$esxName = 'current-esx-name-or-IP'

$hostName = 'new-hostname'

$domainName = 'new-domain'

Connect-VIServer -Server $esxName

$esx = Get-VMHost -Name $esxName

$netSys = Get-View -Id $esx.ExtensionData.ConfigManager.NetworkSystem 

$stack = $esx.ExtensionData.Config.Network.NetStackInstance | where{$_.Key -eq 'defaultTcpipStack'

 

$config = New-Object VMware.Vim.HostNetworkConfig 

$spec = New-Object VMware.Vim.HostNetworkConfigNetStackSpec 

$spec.Operation = [VMware.Vim.ConfigSpecOperation]::edit 

$spec.NetStackInstance = $stack

$spec.NetStackInstance.DnsConfig.HostName = $hostName

$spec.NetStackInstance.DnsConfig.DomainName = $domainName

$netsys.UpdateNetworkConfig($config,[VMware.Vim.HostConfigChangeMode]::modify) 

Disconnect-VIServer -Server $esxName -Confirm:$false


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

Reply
0 Kudos