VMware Cloud Community
dalcowboys
Contributor
Contributor

Grab IP from Virtual Server using CLI vmware-cmd

We can get the IP with a combination of 2 commands. One to list all the .vmx config files on the ESXi host. And 2, grep the hostname you are looking for to get the correct vmx to get the IP for that machine.

Here we go.

Step 1: Grab all the vmx images

root@phvlnxadm01:/root# vmware-cmd -H $vcenter_Hostname -U username@domain​​ --vihost $esxi_hostname -l

Enter password:

/vmfs/volumes/1712a9bd-de62a9a0/fpqa-R0099-008/fpqa-R0099-008.vmx

/vmfs/volumes/1712a9bd-de62a9a0/fpqa-R0098-028/fpqa-R0098-028.vmx

/vmfs/volumes/1712a9bd-de62a9a0/fpqa-R0098-025/fpqa-R0098-025.vmx

/vmfs/volumes/1712a9bd-de62a9a0/RATVHQRTS09/RATVHQRTS09.vmx

/vmfs/volumes/1712a9bd-de62a9a0/fpqa-R0098-023/fpqa-R0098-023.vmx

/vmfs/volumes/1712a9bd-de62a9a0/capqa-R0098-001/capqa-R0098-001.vmx

Step 2: Get the IP of image for fpqa-R0099-008

root@phvlnxadm01:/root# vmware-cmd /vmfs/volumes/1712a9bd-de62a9a0/fpqa-R0099-008/fpqa-R0099-008.vmx getguestinfo ip -H $vcenter_Hostname -U username@domain​ --vihost $esxi_hostname

Enter password:

getguestinfo(ip) = 10.90.78.61

Problem:

We are looking for simpler process to do this. We have multiple ESXi hosts on the vCenter and would like to make with one call using vmware-cmd if we have the vCenter hostname and VM hostname. Can you assist?

Tags (1)
0 Kudos
1 Reply
parmarr
VMware Employee
VMware Employee

You need to use the same commands to get the ESXi Host IP address using the vmware-cmd command.

However, you can use the power cli scripts to get the host IP addresses in an easier method.

Example: Get-VMHost ESXi_Hostname | Sort Name | Get-View | Select Name, @{N="IP Address";E={($_.Config.Network.Vnic | ? {$_.Device -eq "vmk0"}).Spec.Ip.IpAddress}}

Sincerely, Rahul Parmar VMware Support Moderator
0 Kudos