VMware Cloud Community
Kukunga
Contributor
Contributor
Jump to solution

Grabbing VM ipaddress via PowerCLI

Hi All,

I'm familiar with running the following in order to see the IPaddresses for a given VM:

# Grab all VMs through this view

$a = get-view -viewtype virtualmachine

# Suppose the 1st VM has multiple IP addresses

$a[0].guest.ipaddress

That would return me the array of IPaddresses for the given VM.

The issue I'm experiencing currently is when I do this very same thing, the data pulled back is a SINGLE IPaddress for every VM. I can't figure out what has changed. I have confirmed using the Get-VM cmdlet will pull the IPaddress info as I'm accustomed to. I originally chose the VIEW route since I'm dealing with large numbers of VMs and the view was much quicker than the Get-VM cmdlet. If anyone has suggestions or questions please let me know. Thanks for reading!

-Josiah

I'll be hovering in the Freenode IRC #powercli channel for the next day or so 'till this is put to bed to some degree of closure ^.^

PS - Something I have noticed is the $_.guest.net.ipaddress property is not preserved (not sure if that's the right word choice) when taking the get-view and exporting it via CLIXml (export-clixml); in the .xml export this $_.guest.net.ipaddress does not exist from what I see. My original thought was to simply grab all VM-view data from another environment, then export via CliXML, take back to home base & chop it up from there. Looks like I'll need to handle a little more over on the other environment-end before bringing back to home base. Cheers.

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
Wh33ly
Hot Shot
Hot Shot
Jump to solution

Try this :

Get-View -ViewType VirtualMachine |Select @{N='IP';E={[string]::Join(',',$_.Guest.net.IPAddress)}}

Also on my side, I only see one IP address in guest.IPAddress, but in guest.net.IPAddress they are all listed

View solution in original post

6 Replies
LucD
Leadership
Leadership
Jump to solution

Does this return what you expect ?

Get-View -ViewType VirtualMachine |

Select Name,@{N='IP';E={[string]::Join(',',$_.Guest.IPAddress)}}


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

Kukunga
Contributor
Contributor
Jump to solution

Thanks for the reply and suggestion. The piece you provided results in the same. None of the VMs which have more than 1 IP are showing that here.

NameIp
Host-01SingleIp
Host-02SingleIp
Host-03SingleIp
Host-04SingleIp
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Do you see the 2nd IP address in the vSphere client (when you select the VM and look under Summary - General) ?


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

0 Kudos
Kukunga
Contributor
Contributor
Jump to solution

Yes, there are a total of 4 IP's for a few VM's and I see them each in the Summary tab's General section (via the View all option). While I'm able to continue w/my efforts through use of the Get-VM cmdlet, I'm stumped on what's up w/the view. I tried the same efforts in another environment (different ViServer), and a single IP is returned there as well via the view. I don't know what to think >.<

0 Kudos
Wh33ly
Hot Shot
Hot Shot
Jump to solution

Try this :

Get-View -ViewType VirtualMachine |Select @{N='IP';E={[string]::Join(',',$_.Guest.net.IPAddress)}}

Also on my side, I only see one IP address in guest.IPAddress, but in guest.net.IPAddress they are all listed

Kukunga
Contributor
Contributor
Jump to solution

That does it! I imagine I missed something which likely alluded to $_.guest.IpAddress no longer working in some way or another along w/the suggestion to use guest.net.IpAddress in its place. I thank you both for your attention and time/assistance.

Regards,

Josiah

0 Kudos