VMware Cloud Community
EvilEmuofDoom
Contributor
Contributor
Jump to solution

Get a VM's IP address? (when DNS not available)

I have a odd setup where I have a vCenter server running in a private network that doesn't have INTERNAL DNS available. I'm currently running scripts that query an IP range but takes forever to run. I can run get-vm and get all the VMs but can't do anything with them since there is no DNS and I can't find a way to grab a VM's IP address. If I could get IP addresses I could then run functions against them. If it makes a difference these VM's have two nics: Public and Private. Any ideas?

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
alanrenouf
VMware Employee
VMware Employee
Jump to solution

The Get-VM cmdlet returns the IP addresses under the Guest.IPAddress property starting with for the first IP use them as so:

Get-VM |Where {$_.PowerState -eq "PoweredOn" } |foreach { Write "$($_.Name) has an IPAddress of $($_.Guest.IPAddress[0])" }

If you found this information useful, please consider awarding points for Correct or Helpful.

Alan Renouf

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com

View solution in original post

0 Kudos
5 Replies
LucD
Leadership
Leadership
Jump to solution

What OS are these guests running ? Windows ?

If yes, have a look at Cody's latest blog entry on Invoke-VMScript.

Provided you have PowerShell installed on the guests, you can easily get the IP addresses from inside the guest.


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

alanrenouf
VMware Employee
VMware Employee
Jump to solution

The Get-VM cmdlet returns the IP addresses under the Guest.IPAddress property starting with for the first IP use them as so:

Get-VM |Where {$_.PowerState -eq "PoweredOn" } |foreach { Write "$($_.Name) has an IPAddress of $($_.Guest.IPAddress[0])" }

If you found this information useful, please consider awarding points for Correct or Helpful.

Alan Renouf

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com
0 Kudos
EvilEmuofDoom
Contributor
Contributor
Jump to solution

Luc,

I don't think this will work for me since I can't get to those machines by name (VERY cool link though, I can definitely use it elsewhere, thanks!). I had a hard time explaining my situation clearly. Basically say I run Get-VM and it returns with Server1, Server2, Server3, etc. I can't then run anything against those because it tries to use the hostname. I can't seem to find an IP anywhere in Get-VM so I'm looking for alternatives if they exist.

PS - It's hilarious that you replied right away as I was just telling someone next to me that you seem to answer EVERY question in this forum Smiley Wink.

0 Kudos
EvilEmuofDoom
Contributor
Contributor
Jump to solution

Alan,

Seriously? Did I really just miss it in Get-VM somehow?!?! LOL. Thanks, I'll try as soon as I can.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Thanks (I think) Smiley Wink

You don't have to use the hostname nor IP address for the Invoke-VMScript cmdlet.

You do that against the object that is returned by Get-VM

Like this:

Invoke-VMScript -VM (Get-VM Server1) -ScriptText "ipconfig" -HostUser <host-account> -HostPassword <host-password> -GuestUser <guest-user> -GuestPassword <guest-password>

Btw the solution Alan proposed is valid provided you have the VMware Tools installed and running.


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