VMware Cloud Community
alasdair_carnie
Enthusiast
Enthusiast
Jump to solution

Retrieve the IP Address of the Management Nic on ESXi

Hi,

I'm trying to change the IP settings of a new ESXi host from DHCP to static. I've looked at the configuration scripts on the forums, but they appear to rely on getting some of the settings from the local host where the script is executing and that option is not available to me.

I have reserved IP addresses and set the appropriate DHCP settings so that the ESXi host boots up and gets the correct IP address, DNS name, DG, and DNS server settings, but I now need to change them to static.

I need to extract the current settings which are correct and populate the $HostIP and $HostMask variables

Connect-VIServer -Server 172.19.1.101 -User root

$HostIP =

$HostMask =

$VMConsole=Get-VMHostNetwork -ErrorAction Inquire

$ConsoleNIC = $VMConsole | %{$_.VirtualNic} | Where-Object { $_.DeviceName -like "vmk0"}

Set-VMHostNetworkAdapter -VirtualNic $ConsoleNic -IP $HostIP -SubnetMask $HostMask

Any help would me much appreciated.

Thanks,

Alasdair............

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The Get-VMHostNetworkAdapter cmdlet should give you that information.

Something like this

$vmkAdapt = Get-VMHostNetworkAdapter | where {$_.Name -eq "vmk0"}
$HostIP = $vmkAdapt.IP
$HostMask = $vmkAdapt.SubnetMask
$VMConsole=Get-VMHostNetwork -ErrorAction Inquire
$ConsoleNIC = $VMConsole | %{$_.VirtualNic} | Where-Object { $_.DeviceName -eq "vmk0"}
Set-VMHostNetworkAdapter -VirtualNic $ConsoleNic -IP $HostIP -SubnetMask $HostMask

____________

Blog: LucD notes

Twitter: lucd22


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

View solution in original post

0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

The Get-VMHostNetworkAdapter cmdlet should give you that information.

Something like this

$vmkAdapt = Get-VMHostNetworkAdapter | where {$_.Name -eq "vmk0"}
$HostIP = $vmkAdapt.IP
$HostMask = $vmkAdapt.SubnetMask
$VMConsole=Get-VMHostNetwork -ErrorAction Inquire
$ConsoleNIC = $VMConsole | %{$_.VirtualNic} | Where-Object { $_.DeviceName -eq "vmk0"}
Set-VMHostNetworkAdapter -VirtualNic $ConsoleNic -IP $HostIP -SubnetMask $HostMask

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
alasdair_carnie
Enthusiast
Enthusiast
Jump to solution

Thanks Luc.

Can I use a similar method to extract the hostname and set the value of $HostName before setting it with

  1. Set Hostname

Set-VMHostNetwork -Network $VMConsole -DomainName $HostPath -HostName $HostName -DNSFromDHCP $False -ErrorAction Inquire

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can find the hostname indirectly with this line

$HostName = (Get-View $vmkAdapt.VMHostId).Name

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos