VMware Cloud Community
sochry
Enthusiast
Enthusiast

How Do I Determine through the PowerCLI if a Host has a Dynamic or Static IP?

I am using the following to determine if a Host machine is static or dynamic.

$hostView = Get-View -ViewType HostSystem

$networkView = $hostView.Config.Network

$dhcp = $networkView.DnsConfig.Dhcp

However, this does nto appear to be the correct field as even though the host disaply says (STATIC), my $dhcp still returns true in the script.

Confused...

0 Kudos
6 Replies
LucD
Leadership
Leadership

The following script will list for each ESX host and for each pnic on that host wether the IP is obtained through DHCP.

Get-View -ViewType HostSystem | % {
	Write-Host $_.Name
	$_.Config.Network.Pnic | %{
		Write-Host $_.Device $_.Spec.Ip.Dhcp
	}
}


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

0 Kudos
sochry
Enthusiast
Enthusiast

Thanks for weighing in, Luc.

From the ESXi host, I chose Configure Management Network. I selected IP configuration and then made sure to check "Use dyanamic IP address and network configuration". Once the settings were saved, the network was restarted and (DHCP) appeared after the IP on the main console screen.

I then ran the script you provided and received the following output:

localhost.domainname.com

vmnic0 False

vmnic1 False

vmnic2 False

I would have expected them to be true. Why aren't they?

0 Kudos
LucD
Leadership
Leadership

Didn't realise it was for ESXi. Could be an ESXi thing.

What does vicfg-vmknic (from RCLI) say ?

Does that show it correctly ?

Can't really test since I don't have any ESXi with DHCP configured.


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

0 Kudos
sochry
Enthusiast
Enthusiast

I am not familiar with the vicfg-vmknic script. I am still looking into getting a copy of the scripts with which to test.

Steve

0 Kudos
sochry
Enthusiast
Enthusiast

I guess I need more guidance. I have the RCLI installed. What vicfg-vmknic.pl command phrase do I use to determine if it shows up as DHCP or static?

Steve

0 Kudos
LucD
Leadership
Leadership

It seems I was confused as well, the vicfg-vmknic is only for configuring VMKernel NICs.

See also Dave Mishchenko page on RCLI.


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

0 Kudos