VMware Cloud Community
jjen009
Contributor
Contributor

How can I find the DNS Name and IP of a VM using PowerCLI

The VSphere GUI client can tell me what a virtual machine's IP and DNS are. I am trying to find a way to get that information out of "vi tools" Powershell CLI and can't see how. Get-VM can get me the VM and the .NetworkAdapters Property tells me stuff about the adapter(s) on the VM - but I can't see how to find the IP and DNS name.

jj

Tags (3)
0 Kudos
3 Replies
jjen009
Contributor
Contributor

I am making progress Smiley Happy

Get-VMGuest will get me the IP address. How can I get the DNS name that VMWare knows about?

0 Kudos
jjen009
Contributor
Contributor

OK, I have figured it out. Get-VMGuest objects also have a property called 'HostName' which turns out to be what the GUI client displays as DNS.

0 Kudos
esarakaitis
Enthusiast
Enthusiast

how about:

$VMs = Get-VM
foreach ($VM in $VMs){
	$VM = Get-View $VM.ID
	$nm = $VM.name
    $hn = $VM.guest.hostname 
    $ip = $VM.guest.ipaddress
    $vm | select @{Name = "Name"; Expression = {$nm}}, @{Name = "Hostname"; Expression = {$hn}}, @{Name = "IP"; Expression = {$ip}}
    }

http://www.vmwareadmins.com

http://www.vmwarescripting.com

0 Kudos