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?
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
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
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
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 .
Alan,
Seriously? Did I really just miss it in Get-VM somehow?!?! LOL. Thanks, I'll try as soon as I can.
Thanks (I think)
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